<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Metoojava&#039;s Blog</title>
	<atom:link href="http://metoojava.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://metoojava.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sun, 22 Jan 2012 05:36:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='metoojava.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/ca8cbf4e68904311dc2122551c02d177?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Metoojava&#039;s Blog</title>
		<link>http://metoojava.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://metoojava.wordpress.com/osd.xml" title="Metoojava&#039;s Blog" />
	<atom:link rel='hub' href='http://metoojava.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Java 7 Awesome Aspect-Automatic Resource Management</title>
		<link>http://metoojava.wordpress.com/2010/12/19/java-7-awesome-aspect-automatic-resource-management/</link>
		<comments>http://metoojava.wordpress.com/2010/12/19/java-7-awesome-aspect-automatic-resource-management/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 06:07:44 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java 7]]></category>
		<category><![CDATA[automatic resource management]]></category>
		<category><![CDATA[java 7]]></category>
		<category><![CDATA[java 7 automatic resource management]]></category>
		<category><![CDATA[java 7 features]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=358</guid>
		<description><![CDATA[Introduction: In my previous article,” Java 7 Awesome Features” I had missed one of the greatest aspect of Java 7.That is nothing but “Automatic Resource Management”. This article deals with the same. Managing Resource is one of the keen thing in development. Because if we don’t manage the resource effectively it will cause lot of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=358&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em><strong>Introduction:</strong></em></p>
<p>In my previous article,” <a href="http://metoojava.wordpress.com/2010/11/15/java-7-awesome-features/" target="_blank">Java 7 Awesome Features</a>” I had missed one of the greatest aspect of Java 7.That is nothing but “Automatic Resource Management”. This article deals with the same.</p>
<p>Managing Resource is one of the keen thing in development. Because if we don’t manage the resource effectively it will cause lot of issues like PermGen Space Error, TooManyConnections Error etc.</p>
<p>For avoid those problems Java 7 introduce the great aspect “Automatic Resource Management”. By this feature java can automatically manage the resources effectively. So java frees the developer from lots of overhead. Lets have a prolix look on this.</p>
<p><em><strong>Syntax:</strong></em></p>
<p><pre class="brush: jscript;">

try(Resource 1;Resource 2;Resource 3….)

{

//block of statements

}

catch(Exception e)

{

//block of statements

}

</pre></p>
<p>Here is simple code snippet which shows you the typical try-catch-finally block. In the code we create the jdbc connection for access the data from database.</p>
<p><pre class="brush: jscript;">

Connection connection = null;

Statement statement = null;

try

{

connection =    DriverManager.getConnection(“databaseurl”,”username(opt)”,”password(opt)”);

statement = connection.createStatemnet();

boolean executionStatus= statement.execute(“query”);

}

catch(Exception e)

{

//Block of code for handle the exception

e.printStacktrace();

}

finally

{

try

{

statement.close();

connection.close();

}

catch(Exception e)

{

//block of statements for handle exceptions.

}

}

</pre></p>
<p>In the above snippet, suppose we forget to close the statement and connection, what happened? May be after some operations (which also open the connection) “Too Many connection error” will occurred.</p>
<p>But java 7 keeps us in safe zone from those kinds of errors by mange the resource automatically. In java 7 we can write the above snippet like this,</p>
<p><pre class="brush: jscript;">

Connection connection = null;

Statement statement = null;

try(connection =    DriverManager.getConnection(“databaseurl”,”username(opt)”,”password(opt)”);

statement = connection.createStatemnet())

{

boolean executionStatus= statement.execute(“query”);

}

catch(Exception e)

{

//block of statements for handles the exceptions

}

</pre></p>
<p>In the above snippet, there are no overheads like close the connections and statements properly. Java 7 can manage those things automatically for us.</p>
<p><strong>Note:</strong></p>
<blockquote><p>Java 7 mange the resources which are sub interfaces and implementing classes of <a href="http://download.java.net/jdk7/docs/api/java/lang/AutoCloseable.html" target="_blank">AutoCloseable</a>.So we can pass the resources which are extends or implements the interface <a href="http://download.java.net/jdk7/docs/api/java/lang/AutoCloseable.html" target="_blank">AutoCloseable</a>.</p></blockquote>
<p>That’s all folks, I think this article makes you bit more knowledgeable about java 7 awesome aspect “Automatic resource Management”, If you feel the same, please leave your footprints(comments) here. Joyous coding day…..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=358&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/12/19/java-7-awesome-aspect-automatic-resource-management/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple JPA Application with Hibernate</title>
		<link>http://metoojava.wordpress.com/2010/12/05/sample-jpa-application/</link>
		<comments>http://metoojava.wordpress.com/2010/12/05/sample-jpa-application/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 05:19:12 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jpa+mysql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sample application using jpa]]></category>
		<category><![CDATA[Simple JPA Application using Hibernate Vendor support]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=233</guid>
		<description><![CDATA[Introduction: Now I am the newbie to JPA.I learn some thing about JPA. So I wanna share that with you all. So only I am here to do the same. This article deals with how to develop the simple JPA application using hibernate vendor support. Let’s get into that. Prerequisites: JDK 1.5 and above Your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=233&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h5><span style="color:#4682b4;">Introduction:</span></h5>
<p><span style="font-weight:normal;font-size:13px;">Now I am the newbie to JPA.I learn some thing about JPA. So I wanna share that with you all. So only I am here to do the same. This article deals with how to develop the simple JPA application using hibernate vendor support. Let’s get into that.</span></p>
<p><span style="color:#4682b4;"><strong><em>Prerequisites:</em></strong></span></p>
<ul>
<li><strong><em>JDK 1.5 and above</em></strong></li>
<li><strong><em>Your favourite IDE.</em></strong></li>
<li><strong><em>HibernateJPA Library.</em></strong></li>
<li><strong><em>Mysqljdbc.jar</em></strong></li>
</ul>
<p><strong><em>After create the Project we have to add above required libraries and jars into our library folder.</em></strong></p>
<h5><span style="color:#4682b4;"><strong><em>Steps:</em></strong></span></h5>
<ul>
<li><strong><em>Table Creation.</em></strong></li>
<li><strong><em>Creation of  Persistence.xml</em></strong></li>
<li><strong><em>Creation of  Entity class</em></strong></li>
<li><strong><em>Creation of  Entity Manager class</em></strong></li>
<li><strong><em>Creation of  Test class</em></strong><strong><em>.</em></strong></li>
</ul>
<h5><span style="color:#4682b4;"><strong><em>1. Table Creation:</em></strong></span></h5>
<p><strong><em> </em></strong></p>
<p>Create table named “Department”, which contains two columns “departmentId” and “departmentName” by executing the following script,<strong><em> </em></strong></p>
<p><pre class="brush: jscript;">
CREATE TABLE `Department` (
`departmentId` int(10) NOT NULL,
`departmentName` varchar(10) default NULL,
PRIMARY KEY  (`departmentId`))
</pre></p>
<h5><span style="color:#4682b4;">2. Persistence.xml:</span></h5>
<p>This persistence.xml file is act like configuration file for JPA.</p>
<p><pre class="brush: jscript;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;persistence version=&quot;1.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;&gt;

&lt;persistence-unit name=&quot;JPASamplePU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;

&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;

&lt;class&gt;com.bsj.entities.Department&lt;/class&gt;

&lt;properties&gt;

&lt;property name=&quot;hibernate.connection.driver_class&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;

&lt;property name=&quot;hibernate.connection.url&quot; value=&quot;jdbc:mysql://localhost:3306/jpadb&quot;/&gt;

&lt;property name=&quot;hibernate.cache.provider_class&quot; value=&quot;org.hibernate.cache.NoCacheProvider&quot;/&gt;

&lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;update&quot;/&gt;

&lt;property name=&quot;hibernate.connection.username&quot; value=&quot;root&quot;/&gt;

&lt;property name=&quot;hibernate.connection.password&quot; value=&quot;root&quot;/&gt;

&lt;/properties&gt;

&lt;/persistence-unit&gt;

&lt;/persistence&gt;
</pre></p>
<p>Persistence-unit: used to represent the persistence unit.</p>
<p>Transaction-type: type of transaction</p>
<p>There are two type of transactions are avail.</p>
<p>Resource-local: Transactions have to be managed by developer locally.</p>
<p>JTA: Transactions are managed by application server.</p>
<p>Class: Represent the entity.</p>
<p>hbm2ddl.auto: used to perform the action in the database when the SessionFactory is created.</p>
<p>All the others are basic things.</p>
<h5><span style="color:#4682b4;">3. Creation of Entity Class:</span></h5>
<p>Entity class is used to represent the table in class format.</p>
<p><pre class="brush: jscript;">package com.bsj.entities;

import java.io.Serializable;

import javax.persistence.Basic;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.Id;

import javax.persistence.NamedQueries;

import javax.persistence.NamedQuery;

import javax.persistence.Table;

@Entity//Represent the class entity class

@Table(name = &quot;department&quot;)//Represents the table name

@NamedQueries(

{

@NamedQuery(name = &quot;Department.findAll&quot;, query = &quot;SELECT d FROM Department d&quot;), @NamedQuery(name = &quot;Department.findByDepartmentId&quot;, query = &quot;SELECT d FROM Department d WHERE d.departmentId = :departmentId&quot;), @NamedQuery(name = &quot;Department.findByDepartmentName&quot;, query = &quot;SELECT d FROM Department d WHERE d.departmentName = :departmentName&quot;)

})

public class Department implements Serializable

{

private static final long serialVersionUID = 1L;

@Id

@Basic(optional = false)

@Column(name = &quot;departmentId&quot;)

private Integer departmentId;

@Column(name = &quot;departmentName&quot;)

private String departmentName;

public Department()

{

}

public Department(Integer departmentId)

{

this.departmentId = departmentId;

}

public Department(Integer departmentId, String DepartmentName)

{

this.departmentId = departmentId;

this.departmentName = departmentName;

}

//Getter setter method of variables

}
</pre></p>
<h5><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:11px;font-weight:bold;color:#4682b4;">Annotation used in Entity Class:</span></h5>
<p>@Entity – used to represent the class as Entity class. By using this annotation only we can make simple POJO class as Entity class.</p>
<p>@Table – used Represent the table name which the entity class points out.</p>
<p>@Id – Used to represent the primary key field.Only one primary key is allowed in the entity class.</p>
<p>@Column – used to represent the column details such as name, nullable etc.</p>
<h5><span style="color:#4682b4;">QueryAPI:</span></h5>
<p>There are two types of query is avail.<br />
1. Static (Named) Queries: defined statically with the help of annotation (or XML) before the entity class.</p>
<p>A name of the Query  is usually given to the query definition so that other components in the same persistent unit can refer the query by the name.<br />
2. Dynamic queries: are nothing but whose query strings are provided at run-time</p>
<p><span style="color:#4682b4;">4.Creation of Entity Manager Class:</span></p>
<p><span style="color:#4682b4;"> </span>The constructor has the Entity Manager Factory as argument and it allows us to create the Entity Manager.</p>
<p>The Entity Manager class is transaction scoped bean so we have to begin transaction before each action and commit transaction after each operation.</p>
<p><pre class="brush: jscript;">package com.bsj.entities;

import java.util.List;

import javax.persistence.EntityManager;

import javax.persistence.EntityManagerFactory;

import javax.persistence.Query;

public class DepartmentManager

{

private EntityManager em;

public DepartmentManager(EntityManagerFactory emf)

{

em = emf.createEntityManager();

}

/**

* Method used to create department.

* @param department

*/

public void createDepartment(Department department)

{

//Begin Transaction

System.out.println(&quot;Creation : &quot;);

em.getTransaction().begin();

em.persist(department); //Persist entity in persistence context.

//Commit Transaction

em.getTransaction().commit();

System.out.println(&quot;Department Created SuccessFully&quot;);

}

/**

* Method used to search department Name by id.

* @param id

* @return

*/

public Department searchById(Integer id)

{

//Method used to find data

return em.find(Department.class, id);

}

public void updateUser(Department department)

{

System.out.println(&quot;Update : &quot;);

em.getTransaction().begin();

em.merge(department);

em.getTransaction().commit();

System.out.println(&quot;Update successfully.&quot;);

}

public void removeUser(Department department)

{

em.getTransaction().begin();

em.remove(department);

em.getTransaction().commit();

System.out.println(&quot;Remove department successfully&quot;);

}

public List getAll()

{

Query query = em.createQuery(&quot;select a from Department a&quot;);

List list = query.getResultList();

return list;

}

public void close()

{

em.close();

}

}

</pre></pre>
<h5><span style="color:#749bc1;">Methods used in Entity Manager:</span></h5>
<p>Persist(entityObject)-Used to persist entity in the persistence context.<br />
Find (Entityclass,value) – Find the datas regarding the input passed as argument.<br />
merge(entityobject) : Update the database regarding to the passing details.<br />
<span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:11px;font-weight:bold;color:#4682b4;">5.Creation of Test class:</span></p>
<p>We can get the entity manager factory by the  createEntityManagerFactory method of the class Persistence,<br />
createEntityManagerFactory(persistence unit name);<br />
This method has the persistence unit name as argument.<br />
Call the entity manager methods by using the reference of entity manager.</p>
<p><pre class="brush: jscript;">package com.bsj.tester;

import com.bsj.entities.Department;

import com.bsj.entities.DepartmentManager;

import java.util.Iterator;

import java.util.List;

import javax.persistence.EntityManagerFactory;

import javax.persistence.Persistence;

public class TestJPA

{

private DepartmentManager departmentManager;

private EntityManagerFactory emf;

/**

* Method to setup basic thing need for implementation like entiny manager

* factory,entity manager etc.

* @throws Exception

*/

protected void setUp() throws Exception

{

/**

* Create the entity manager factory with the help of persistence.

* @Param NameofPersistence unit form Persistence.xml

*/

emf = Persistence.createEntityManagerFactory(&quot;JPASamplePU&quot;);

/**

* create Departmanager

* @Param Entity Manager Factory

*/

departmentManager = new DepartmentManager(emf);

}

/**

* Method to close entity manager and entity manager factory.

* (i.e) Remove from the persistence context

* @throws Exception

*/

protected void close() throws Exception

{

departmentManager.close();

emf.close();

}

/**

* Method for test the application.

*/

public void test()

{

/**

* Create the Entity by using constructor of Entity.

*/

Department department = new Department(10, &quot;Chemical&quot;);

departmentManager.createDepartment(department);

System.out.println(&quot;Before Update :&quot;);

Department searchDepartment = departmentManager.searchById(50);

System.out.println(&quot;Department Name of Id 50 : &quot; + searchDepartment.getDepartmentName());

searchDepartment.setDepartmentName(&quot;EEE&quot;);

departmentManager.updateUser(department);

department = departmentManager.searchById(50);

System.out.println(&quot;After update.&quot;);

System.out.println(&quot;Department Name of Id 50 : &quot; + searchDepartment.getDepartmentName());

List list = departmentManager.getAll();

System.out.println(&quot;Number of Departments: &quot; + list.size());

System.out.println(&quot;List of Departments : &quot;);

Iterator iterator = list.iterator();

while (iterator.hasNext())

{

Department department3 = (Department) iterator.next();

System.out.println(&quot;Id : &quot; + department3.getDepartmentId());

System.out.println(&quot;Name : &quot; + department3.getDepartmentName());

}

}

public static void main(String args[])

{

System.out.println(&quot;Inside TestJPA main&quot;);

TestJPA testJPA = new TestJPA();

try

{

testJPA.setUp();

testJPA.test();

testJPA.close();

}

catch (Exception e)

{

e.printStackTrace();

}

System.out.println(&quot;End of TestJPA main&quot;);

}

}
</pre></p>
<p>Thats all folks.If you found this article was helpful to you,don't forget to leave your valuable comments here.Happy coding....</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/233/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/233/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/233/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=233&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/12/05/sample-jpa-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring&#8217;s  Before and After Advice</title>
		<link>http://metoojava.wordpress.com/2010/11/30/springs-before-and-after-advice/</link>
		<comments>http://metoojava.wordpress.com/2010/11/30/springs-before-and-after-advice/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 15:38:14 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Aspect Oriented Programming]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring AOP concepts]]></category>
		<category><![CDATA[advice]]></category>
		<category><![CDATA[after advice]]></category>
		<category><![CDATA[after finally advice]]></category>
		<category><![CDATA[after returning advice]]></category>
		<category><![CDATA[afterthrowing advice]]></category>
		<category><![CDATA[around advice]]></category>
		<category><![CDATA[aspect]]></category>
		<category><![CDATA[before advice]]></category>
		<category><![CDATA[jointpoint]]></category>
		<category><![CDATA[point cut]]></category>
		<category><![CDATA[spring.aop]]></category>
		<category><![CDATA[target]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=299</guid>
		<description><![CDATA[Introduction: This article makes you bit more knowledgeable in one of the spring’s Aspect Oriented Programming concept advice. In this article we see the simple example for the advice aspect of Spring AOP framework. Before that we have a brief look at some AOP concepts that enrich your understanding. Aspect: It’s just like a class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=299&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4><span style="color:#888888;">Introduction:</span></h4>
<p>This article makes you bit more knowledgeable in one of the spring’s Aspect Oriented Programming concept advice. In this article we see the simple example for the advice aspect of Spring AOP framework. Before that we have a brief look at some AOP concepts that enrich your understanding.</p>
<h5><span style="color:#888888;">Aspect:</span></h5>
<p>It’s just like a class in OOPs concepts.</p>
<h5><span style="color:#888888;">Joint point:</span></h5>
<p>A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.</p>
<p>In real world example, it’s just like a menu items in the menu card.</p>
<h5><span style="color:#888888;">Pointcut:</span></h5>
<p>Combination of joinpoints which are chosen for execution.</p>
<p>In real world example, it’s just like a meal which is combination of items chosen from menu card.</p>
<h5><span style="color:#888888;">Target:</span></h5>
<p>The class which is going to be advised.</p>
<p><span style="color:#888888;">Advice:</span></p>
<p>Actions taken by an aspect at a particular joinpoint.The advices are classified into three major groups.</p>
<ul>
<li>Before advice</li>
<li>After advice</li>
<li>Around advice</li>
</ul>
<h5><span style="color:#888888;">Before advice:</span></h5>
<p>Before advice is executed before the execution of methods in the target.</p>
<h5><span style="color:#888888;">After advice:</span></h5>
<p>After advice is executed after the execution of methods in target. Normally before advice and after advices are used to logging feature. It’s classified into three subgroups.</p>
<p>Types:</p>
<ul>
<li>After returning advice</li>
<li>After throwing advice</li>
<li>After (finally) advice</li>
</ul>
<h5><span style="color:#888888;">Around Advice:</span></h5>
<p>Around advice is executed before and after execution. Its the powerful form of advice. We have a explanation in our next meet.</p>
<p>It is also responsible for choosing whether to proceed to the join point or to block the advised method execution by returning its own return value or throwing an exception. All other advices cannot block the execution flow.</p>
<p>Lets see the example for before and after returning advices.</p>
<p><span style="color:#888888;"><strong><em>Prerequisites:</em></strong></span></p>
<p>JDK 1.5 and Above</p>
<p>Your favourite IDE</p>
<p><a title="Spring jars" href="http://www.springsource.org/download">spring latest  jars</a></p>
<p><a title="commons logging.jar" href="http://www.java2s.com/Code/Jar/ABC/commons-logging.jar.htm">commons-logging.jar</a></p>
<p><a href="http://mirrors.ibiblio.org/pub/mirrors/maven2/org/springframework/spring-aop/1.2.6/spring-aop-1.2.6.jar">spring-aop-1.2.6.jar</a></p>
<p>SpringAOPInterface.java:</p>
<p>An ordinary interface.</p>
<p><pre class="brush: jscript;">
package com.info.spring.aop;
public interface SpringAopInterface
{
public void sayHello(String name);
}
</pre></p>
<p>SpringAOPImpl.java:</p>
<p>An ordinary implementation class of an interface SpringAOPInterface.</p>
<p><pre class="brush: jscript;">

package com.info.spring.aop;
public class SpringAopImpl implements SpringAopInterface{
 public void sayHello(String name)

{

System.out.println(&quot;Hello ,&quot;+name);

}}

</pre></p>
<p>BeforeAdvisor.java:</p>
<p>A class which represent the before advise.By implementing the MethodBeforeAdvice interface make the POJO class as a before advisor class.</p>
<p>The action which is wants to perform in the before advise class is define in the override method before().</p>
<p><pre class="brush: jscript;">

package com.info.spring.aop;
import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class BeforeAdvisor implements MethodBeforeAdvice

{
 public void before(Method method, Object[] os, Object o) throws Throwable

{

System.out.println(&quot;Before Advisor called&quot;);

}}

</pre></p>
<p>AfterAdvisor.java:</p>
<p>A class which represent the after advise.Like a before advisor  class by implementing the AfterReturningAdvice interface make the POJO class as a after advisor class.</p>
<p>The action which is wants to perform in the after advise class is define in the override afterReturning().</p>
<p><pre class="brush: jscript;">

package com.info.spring.aop;
import java.lang.reflect.Method;

import org.springframework.aop.AfterReturningAdvice;
public class AfterAdvisor implements AfterReturningAdvice

{
 public void afterReturning(Object o, Method method, Object[] os, Object o1) throws Throwable

{

System.out.println(&quot;After advisor called&quot;);

}}

</pre></p>
<p>IOC Container Configuration:</p>
<p>This is the context configuration file of the application.Its have to be stored in META-INF folder in src package.</p>
<p>Target: represents the bean class which is going to be advised by the advisors.</p>
<p>Interceptor Names: Represent the advisor classes list.</p>
<p>advice: Represent the advisor class and the pattern of the bean classes which are going to be advised.</p>
<p>applicationContext.xml:</p>
<p><pre class="brush: jscript;">

&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;

xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd&quot;&gt;

&lt;!-- Bean configuration --&gt;
&lt;bean id=&quot;businesslogicbean&quot;&gt;
&lt;property name=&quot;proxyInterfaces&quot;&gt;
&lt;value&gt;com.info.spring.aop.SpringAopInterface&lt;/value&gt;
&lt;/property&gt;

&lt;!--Target : Reprsent the bean class which is going to be advised--&gt;
&lt;property name=&quot;target&quot; ref &quot;beanTarget&quot; /&gt;
&lt;!--Denotes the list of advices--&gt;
&lt;property name=&quot;interceptorNames&quot;&gt;
&lt;list&gt;
&lt;value&gt;beforeAdvisor&lt;/value&gt;
&lt;value&gt;afterAdvisor&lt;/value&gt;
&lt;/list&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;!-- Bean Classes --&gt;
&lt;bean id=&quot;beanTarget&quot; class=&quot;com.info.spring.aop.SpringAopImpl&quot;/&gt;

&lt;!-- Advisor pointcut definition for before advice --&gt;
&lt;bean id=&quot;beforeAdvisor&quot; class=&quot;org.springframework.aop.support.RegexpMethodPointcutAdvisor&quot;&gt;
 &lt;!--Property which represent the advice--&gt;
 &lt;property name=&quot;advice&quot; ref=&quot;beforeAdvice&quot;/&gt;

 &lt;!--Pattern fot the class which is going to be advised.
 Here any kind of classes are going to be advised.--&gt;
 &lt;property name=&quot;pattern&quot;&gt;
 &lt;value&gt;.*&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;!-- Advisor pointcut definition for before advice --&gt;
&lt;bean id=&quot;afterAdvisor&quot; class=&quot;org.springframework.aop.support.RegexpMethodPointcutAdvisor&quot;&gt;
 &lt;property name=&quot;advice&quot; ref=&quot;afterAdvice&quot;/&gt;
 &lt;property name=&quot;pattern&quot;&gt;
 &lt;value&gt;.*&lt;/value&gt;
 &lt;/property&gt;
 &lt;/bean&gt;

  &lt;!-- Advice classes --&gt;
&lt;bean id=&quot;beforeAdvice&quot;
class=&quot;com.info.spring.aop.BeforeAdvisor/&gt;
&lt;bean id=&quot;afterAdvice&quot;
class=&quot;com.info.spring.aop.AfterAdvisor&quot;/&gt;
&lt;/beans&gt;
</pre></p>
<p>Tester.java:</p>
<p>By passing the path of the applicationcontext file to theclass ClassPathXmlApplicationContext,  we can get the instance of Application context.</p>
<p>By the method of getBean() of ApplicationContext,we can retrieve the instance of the bean&#8217;s interface.We have to pass the id of the bean as the argument to the method getBean().By using the instance of the bean&#8217;s interface we can call the method of the interface which is defined in the bean class.</p>
<p><pre class="brush: jscript;">

package com.info.spring.aop;
import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Tester

{
 public static void main(String[] args)

{

// Read the configuration file

ApplicationContext ctx = new ClassPathXmlApplicationContext(&quot;META-INF/applicationContext.xml&quot;);

 // Instantiate an object

SpringAopInterface springAopInterface =  (SpringAopInterface) ctx.getBean(&quot;businesslogicbean&quot;);
 // Execute the public method of the bean

springAopInterface.sayHello(&quot;Munees&quot;);

}}

</pre></p>
<p>Thats all folks,I think its give some idea about the spring AOP&#8217;s advice aspect.If you feel this article is helpful to you,Don&#8217;t forget to leave your footprints(comments) here.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=299&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/11/30/springs-before-and-after-advice/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Bean Automatic Detection using context:component-scan element</title>
		<link>http://metoojava.wordpress.com/2010/11/27/spring-bean-automatic-detection-using-component-scan-element/</link>
		<comments>http://metoojava.wordpress.com/2010/11/27/spring-bean-automatic-detection-using-component-scan-element/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 12:37:01 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring AOP concepts]]></category>
		<category><![CDATA[@autowired]]></category>
		<category><![CDATA[@component]]></category>
		<category><![CDATA[@controller]]></category>
		<category><![CDATA[@repository]]></category>
		<category><![CDATA[@service]]></category>
		<category><![CDATA[applicationcontext.xml]]></category>
		<category><![CDATA[automatic detection of spring beans]]></category>
		<category><![CDATA[component creation]]></category>
		<category><![CDATA[ioc container]]></category>
		<category><![CDATA[spring beans]]></category>
		<category><![CDATA[spring component]]></category>
		<category><![CDATA[stereo type annotation]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=281</guid>
		<description><![CDATA[Introduction: In Spring 3.0, the IOC container can be configured in two ways, They are XML Based Configuration Java Based Configuration. If we go for XML Based Configuration, the sizes of the xml configuration file is so excess for large applications. But we can reduce the size of the xml configuration file by using Spring’s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=281&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4><span style="color:#888888;">Introduction:</span></h4>
<p>In Spring 3.0, the IOC container can be configured in two ways, They are</p>
<ul>
<li>XML Based Configuration</li>
<li>Java Based Configuration.</li>
</ul>
<p>If we go for XML Based Configuration, the sizes of the xml configuration file is so excess for large applications. But we can reduce the size of the xml configuration file by using Spring’s one of the greatest aspect, automatic detection of Spring beans(classes).</p>
<p>This can be achieved by using context:component-scan element in xml configuration file and @component annotation in bean classes. This article deals with spring bean automatic detection using context:component-scan element. Let’s get over that.</p>
<h4><span style="color:#888888;"><strong><em>Prerequisites:</em></strong></span></h4>
<p>JDK 1.5 and Above</p>
<p>Your favourite IDE</p>
<p><a title="Spring jars" href="http://www.springsource.org/download">spring latest  jars</a></p>
<p><a title="commons logging.jar" href="http://www.java2s.com/Code/Jar/ABC/commons-logging.jar.htm">commons-logging.jar</a></p>
<p><a title="aopalliance.jar" href="http://www.java2s.com/Code/Jar/ABC/aopalliance.jar.htm">aopalliance.jar</a></p>
<h4><span style="color:#888888;">Creation of component using @Component annotation:</span></h4>
<p><span style="color:#99ccff;"> </span></p>
<p>By using @component annotation,we can make the bean class as component.By the same way,the below operator bean class make it as component.</p>
<p>Operator.java</p>
<p><pre class="brush: jscript;">

package com.bsj.componentscan;

import org.springframework.stereotype.Component;

/**
 * @author Jhothi
 */
@Component(&quot;operator&quot;)
public class Operator
{
 public int add(int i,int j)
 {
 return i+j;
 }
 public int subtract(int i,int j)
 {
 return i-j;
 }

 public int multiply(int i,int j)
 {
 return i*j;
 }

 public int divide(int i,int j)
 {
 return i/j;
 }
}

</pre></p>
<p>By using auto wired feature of spring we can represent our Operator class as dependency of Calculator class.</p>
<p>By using @Autowired annotation we can make the dependency Operator class as Auto wired one.</p>
<p>Calculator.java</p>
<p><pre class="brush: jscript;">

package com.bsj.componentscan;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author Jhothi
 */
@Component(&quot;calculator&quot;)
public class Calculator
{
 @Autowired
 private Operator operator;
 public void calculation(int i, int j)
 {
 System.out.println(&quot;i+j : &quot; + operator.add(i, j));
 System.out.println(&quot;i-j : &quot; + operator.subtract(i, j));
 System.out.println(&quot;i*j : &quot; + operator.multiply(i, j));
 System.out.println(&quot;i/j : &quot; + operator.divide(i, j));
 }

 /**
 * @param operator the operator to set
 */
 public void setOperator(Operator operator)
 {
 this.operator = operator;
 }
}
</pre></p>
<p><span style="color:#888888;">Note:</span><br />
The component annotation has the name of the component with in the bracket with quotes. The component name is used for detect the bean by the method getBean() of ApplicationContext.For ex,In @Component (&#8220;calculator&#8221;), calculator is the name of the component.</p>
<h4><span style="color:#888888;">Container Configuration:</span></h4>
<p>The IOC container configuration xml file is shown below,The container has the &lt;context:component-scan&gt; element and &lt;context:annotation-config/&gt;</p>
<p>&lt;context:annotation-config/&gt; used to intimate the beans of this IOC container are annotation supported.</p>
<p>By pass the base path of the beans as the value of the base-package attribute of context:component-scan element, we can detect the beans and registering their bean  definitions automatically without lots of overhead.</p>
<p>The value of base-package attribute is fully qualified package name of  the bean classes. We can pass more than one package names by comma  separated like the below one.</p>
<p><pre class="brush: jscript;">

&lt;context:component-scan base-package=&quot;package1, package2&quot;/&gt;

</pre></p>
<p>applicationContext.xml:</p>
<p><pre class="brush: jscript;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
 xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
 xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
 xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd&quot;&gt;

 &lt;context:component-scan base-package=&quot;com.bsj.componentscan&quot;/&gt;
 &lt;context:annotation-config/&gt;
&lt;/beans&gt;

</pre></p>
<p>Finally the @component is one of the stereotype annotations. Some other stereotype annotations are avail. They are @Repository, @Service, and @Controller. The next article deals the stereo type annotaions.Before that if you feel this article is helpful to you doesn’t forget to leave your valuable comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/281/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=281&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/11/27/spring-bean-automatic-detection-using-component-scan-element/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Java 7 awesome Features</title>
		<link>http://metoojava.wordpress.com/2010/11/15/java-7-awesome-features/</link>
		<comments>http://metoojava.wordpress.com/2010/11/15/java-7-awesome-features/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 14:33:59 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Java 7]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[java 7]]></category>
		<category><![CDATA[java 7 features]]></category>
		<category><![CDATA[java advanced features]]></category>
		<category><![CDATA[multi catch]]></category>
		<category><![CDATA[null safe method]]></category>
		<category><![CDATA[project coin]]></category>
		<category><![CDATA[strings in switch]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=205</guid>
		<description><![CDATA[Whenever, I am crawl through the web i notice the word java 7.Then,I really found out java 7 is today’s hot topic. So i googled it for know something about java 7.At that time i found out some thing interested and useful features in java 7.Thats push me here to share something to you all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=205&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Whenever, I am crawl through the web i notice the word java 7.Then,I really found out java 7 is today’s hot topic. So i googled it for know something about java 7.At that time i found out some thing interested and useful features in java 7.Thats push me here to share something to you all folks.Lets get into the topic.</p>
<p>The project name of java 7 development is Project Coin.I have listed some of the features below.</p>
<p><span style="color:#1a5fe4;"><em><strong>Null-safe Method invocation:</strong></em></span></p>
<p>This is the greatest feature which is going to added in Java 7.NullPoniterException is one of the most common exception encountered in Java programming.</p>
<p>When I searched “NullPointerException” in Google, it gave about <span style="color:#1a5fe4;">5,570,000</span> results! This proves how pervasive the exception is and how much effort a developer has to put in writing java code free from null pointer exception.</p>
<p>Suppose if java has a feature to keep us in safe zone from null pointer exception, how is it? It happens.</p>
<p>Suppose we have a method to fetch postal code of a person’s address:</p>
<p><pre class="brush: jscript;">
public String getPostcode(Person person)
{
if (person != null)
{
Address address = person.getAddress();
if (address != null)
{
return address.getPostcode();
}}
return null;
}
</pre></p>
<p>Now check the above syntax. We have done lots of if (null! = object) checks to avoid NullPointerException.</p>
<p><pre class="brush: jscript;">
public String getPostcode(Person person)
{
return person?.getAddress()?.getPostcode();
}
</pre></p>
<p>Null-ignore invocation is concerned with dealing with possible null values in calling one or especially a chain of methods. Check the syntax?. while calling method on an object. This is Null-safe operator in Java 7. Thus, you can avoid lots of if (null!= object) checks in Java 7.</p>
<p><span style="color:#1a5fe4;"><em><strong>Strings in Switch Statements:</strong></em></span></p>
<p>Whenever i am working with switch-case i felt, if the case allowed the string as a case variable we feel so comfort on that. Because the switch case allows only the primitive data types as variable such as integer, char etc.</p>
<p>Whenever i working with the methods that returns status of the operations like succesful, failed like that. At that time i need to convert that in to constants. Then only i can move on switch statements.</p>
<p>But java 7 offers the Strings as case variables in Switch Statements, So we are free from the conversion process.</p>
<p><span style="color:#1a5fe4;">Multi-Exception Catch:</span></p>
<p><span style="color:#0000ff;"> </span></p>
<p>Another awesome update is Multi-Exception Catch, that means a single catch can handle multiple exceptions. The syntax is</p>
<p><pre class="brush: jscript;">
try
{
block of statments
}
catch(Exception1|Exception2|Exception3...)
{
block of statements.
}
</pre></p>
<p>It save lot of spaces in the code.</p>
<p><span style="color:#1a5fe4;"><em><strong>Bracket Notation for Collections:</strong></em><span style="font-weight:normal;font-size:12px;"><em><strong> </strong></em></span></span></p>
<p><span style="color:#1a5fe4;"><span style="font-weight:normal;font-size:12px;"><em><strong> </strong></em></span></span> This feature refers to the ability to reference a particular item in a Collection with square brackets similar to how Arrays are accessed.   Collection is one of the key concepts in java.</p>
<p>But when i was a student, I feel so discomfort with collections because of its strutcture.Thats some thing different from basic things in java.</p>
<p>But now its also be like a simple things like array etc.  For ex, a Collection class we might consider something similar to arrays.</p>
<p>Instead of:</p>
<p><pre class="brush: jscript;">
Collection&lt;String&gt; c = new ArrayList();
c.add(“one”);
c.add(“two”);
c.add(“three”);
Use:
Collection&lt;String&gt; c = new ArrayList {“one”, “two”, “three” };

</pre></p>
<p>Thats all folks.If any important updates are missing don&#8217;t hesitate to add that as comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=205&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/11/15/java-7-awesome-features/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Java code to Wrap and Rotate image in PDF File</title>
		<link>http://metoojava.wordpress.com/2010/08/02/java-code-to-wrap-image-in-pdf-file/</link>
		<comments>http://metoojava.wordpress.com/2010/08/02/java-code-to-wrap-image-in-pdf-file/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 15:02:59 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[how to insert image in pdf]]></category>
		<category><![CDATA[how to place image in pdf file]]></category>
		<category><![CDATA[How to rotate image in pdf file]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image in pdf]]></category>
		<category><![CDATA[itext]]></category>
		<category><![CDATA[java code to wrap image in pdf]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[rotate]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=191</guid>
		<description><![CDATA[Introduction: Now-a-days if we wanna develop an application, that application must have the capability to prefer the Reports. All the reports are  favour to PDF format. If we develop a report for a particular concern the client needs to place their logo in the report. For that we need to insert the image in PDF [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=191&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em><strong>Introduction:</strong></em></p>
<p><em><strong> </strong></em></p>
<p><em>Now-a-days if we wanna develop an application, that application must have the capability to prefer the Reports. All the reports are  favour to PDF format. If we develop a report for a particular concern the client needs to place their logo in the report. For that we need to insert the image in PDF file. This article deals the same<strong>.</strong></em></p>
<p><em>The itex.jar makes it most simple and elegant.</em></p>
<p><em><strong> </strong></em></p>
<p><em><strong>Prerequisites:</strong></em></p>
<p><em><strong> </strong></em></p>
<p><em>JDK 1.5 and Above</em></p>
<p><em>Jar : itext.jar(<a href="http://itextpdf.com/" target="_blank">Download here</a>)</em></p>
<p><em>To make a program over this, firstly we need to import some packages. Remember to make this program the first and foremost thing to remember is to place the iText.jar in WEB-INF/lib of your web application.</em></p>
<p><em>Without this .jar the application will not run.</em></p>
<p><em><strong>Steps involved in Insert image in PDF File:</strong></em></p>
<p><em><strong>Create Document :</strong></em></p>
<p><em>This class describes a PDF file’s page size, margins, and other important attributes. It works as a container for a document&#8217;s chapters, sections, images, paragraphs, and other content. </em></p>
<p><em> </em></p>
<p><em><strong>Create PdfWriter:</strong></em></p>
<p><em> This class is used to create the pdf file.</em></p>
<p><em>By using the method<span style="color:#ff0000;"><span style="color:#00ccff;"> getInstace</span> </span>we can create pdf file from the given output stream.</em></p>
<p><em><strong>Open pdf File:</strong></em></p>
<p><em>Now open the document by using<span style="color:#00ccff;"> open() </span>method in document class.</em></p>
<p><em><strong>Get the Image content:</strong></em></p>
<p><em>By using the method<span style="color:#ffffff;"> <span style="color:#00ccff;">getInstace()</span></span><span style="color:#00ccff;"> </span>of image class we can get the image content.</em></p>
<p><em>The method has the image filename as argument.</em></p>
<p><em><strong>Add contents to Pdf File:</strong></em></p>
<p><em>By using<span style="color:#00ccff;"> add </span>method in document class we can add paragraph and image in the pdf file.</em></p>
<p><em><strong>Resize the image:</strong></em></p>
<p><em>By using the<span style="color:#ffffff;"><span style="color:#00ccff;"> scaleAbsolute()</span> </span>method we can resize the image. We can pass the width and height as the argument to resize the image.</em></p>
<p><em><strong>Rotate image:</strong></em></p>
<p><em>By using<span style="color:#00ccff;"> setRotationDegrees() </span>method of image class we can set the degree which we want to rotate the image. </em></p>
<p><em>After rotate the image we add the image into the pdf file by using add method of document class.</em></p>
<p><em>Code:</em></p>
<p><pre class="brush: jscript;">
package com.bsj.itext;

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

/**
 *
 * @author Muneeswaran
 */
public class WrapImageinPdf
{
 public static void main(String arg[]) throws Exception
 {
 //Create Document
 Document document = new Document(PageSize.A4.rotate());
 //Create PdfWriter:
 PdfWriter.getInstance(document, new FileOutputStream(&quot;imagePdf.pdf&quot;));
 Font font = new Font(Font.TIMES_ROMAN, 18, Font.BOLD);
 //Open pdf File:
 document.open();
 Paragraph paragraph = new Paragraph(&quot;Original:&quot;, font);
 Paragraph par = new Paragraph(&quot;After rotate:&quot;, font);
 //Get the Image content:
 Image image = Image.getInstance(&quot;2.jpg&quot;);
 //Add contents to Pdf File:
 document.add(paragraph);
 document.add(image);
 document.add(par);
 //Resize the image:
 image.scaleAbsolute(500.0f, 500.0f);
 image.setBorder(1);
 //Rotate image:
 image.setRotationDegrees(45.0f);
 document.add(image);
 document.close();
 }
}
</pre></p>
<p>Output:</pre>
<p><em><strong><a href="http://metoojava.files.wordpress.com/2010/08/output.png"><img title="output" src="http://metoojava.files.wordpress.com/2010/08/output.png?w=300&#038;h=168" alt="" width="300" height="168" /></a></strong></em></p>
<p>I hopes this helps.Go ahead to prefer report and inserting logo in pdf.Before that,<strong>if you feel it useful,leave your foot prints here[Comments].</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/191/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=191&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/08/02/java-code-to-wrap-image-in-pdf-file/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>

		<media:content url="http://metoojava.files.wordpress.com/2010/08/output.png?w=300" medium="image">
			<media:title type="html">output</media:title>
		</media:content>
	</item>
		<item>
		<title>Execute Javascript from Java</title>
		<link>http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/</link>
		<comments>http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 08:56:37 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[eval]]></category>
		<category><![CDATA[execute javascript from java]]></category>
		<category><![CDATA[how to access javascript in java]]></category>
		<category><![CDATA[How to execute javascript from java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ScriptEngine]]></category>
		<category><![CDATA[ScriptEnginManager]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=176</guid>
		<description><![CDATA[After a small gap,I am back to here for share something to you all.A week before i have stuck with execute javascript from java.I google it for this.Finally i found my way to achieve this. Java provides the way to execute JavaScript also.The solution is come along with ScriptEngineManager.This article deals the same. The ScriptEngineManager [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=176&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a small gap,I am back to here for share something to you all.A week before i have stuck with execute javascript from java.I google it for this.Finally i found my way to achieve this.</p>
<p>Java provides the way to execute JavaScript also.The solution is come along with ScriptEngineManager.This article deals the same.</p>
<p>The ScriptEngineManager comes along with the package javax.script.</p>
<p>This is a relatively small, simple API. A ScriptEngineManager object can discover script engines through the jar file service discovery mechanism. It can also instantiate ScriptEngine objects that interpret scripts written in a specific scripting language. The simplest way to use the scripting API is as follows:</p>
<ul>
<li> Create a ScriptEngineManager object.</li>
<li> Get a ScriptEngine object from the manager.</li>
<li> Evaluate script using the ScriptEngine&#8217;s eval methods.</li>
</ul>
<p>Now we look at the sample code.</p>
<p><pre class="brush: jscript;">


import javax.script.*;
public class ExecuteScript {
 public static void main(String[] args) throws Exception {
 // create a script engine manager
 ScriptEngineManager factory = new ScriptEngineManager();
 // create a JavaScript engine
 ScriptEngine engine = factory.getEngineByName(&quot;JavaScript&quot;);
 // evaluate JavaScript code from String
 engine.eval(&quot;print('Welocme to java world')&quot;);
 }
}
</pre></p>
<p><span style="color:#00ffff;"><strong>Executing a Script from .js File:</strong></span></p>
<p>In this example, we can execute JavaScript which is from .js file.This can be achieved by the<span style="color:#00ffff;"><strong> eval</strong></span> method of ScriptEngine Class.<br />
The <span style="color:#c0c0c0;"><strong><span style="color:#00ffff;">eval</span> </strong></span>method have the <span style="color:#00ffff;"><strong>FileReader</strong> </span>object as argument.</p>
<p>we can create the ScriptEngineManager and get the ScriptEngine from the above code(line 4-7).</p>
<p>Then we add the eval method which is used to execute script from .js file.</p>
<p><pre class="brush: jscript;">


// evaluate JavaScript code from given file
 engine.eval(new java.io.FileReader(&quot;welcome.js&quot;));
</pre></p>
<p>Let us assume that we have the file named &#8220;welcome.js&#8221; with the following text:</p>
<p><pre class="brush: jscript;">

println(&quot;Welcome to java world&quot;);
</pre></p>
<p>If we will run the code,this yields the output as</p>
<p><pre class="brush: jscript;">

Welcome to java world.

</pre></p>
<p>I hopes this helps.Then Go ahead to execute your JavaScript by using your java code.Before that,<span style="color:#00ffff;"><strong>if you feel it useful,leave your foot prints here[Comments].</strong></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=176&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/06/20/execute-javascript-from-java/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular Expression Symbols</title>
		<link>http://metoojava.wordpress.com/2010/04/17/160/</link>
		<comments>http://metoojava.wordpress.com/2010/04/17/160/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 12:22:04 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=160</guid>
		<description><![CDATA[Introduction: &#8220;Regular expressions&#8221; are combination of special characters and symbols used for pattern matching. i.e., you specify a particular combination of such characters and symbols (= regular expression) and the compiler will search for that string of words through the text data. The following is a very short, and hopefully easy-to-follow, introduction to some of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=160&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction:</h3>
<p>&#8220;Regular expressions&#8221; are combination of special characters and symbols used for pattern matching. i.e., you specify a particular combination of such characters and symbols (= regular expression) and the compiler will search for that string of words through the text data. The following is a very short, and hopefully easy-to-follow, introduction to some of the most useful regular expressions.</p>
<h3>1. Common matching symbols</h3>
<p><strong>Table 1. </strong></p>
<table border="1" cellpadding="0">
<thead>
<tr>
<td><strong>Regular Expression</strong></td>
<td><strong>Description</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>.</td>
<td>Matches any sign</td>
</tr>
<tr>
<td>^regex</td>
<td>regex must match at the beginning of the line</td>
</tr>
<tr>
<td>regex$</td>
<td>Finds regex must match at the end of the line</td>
</tr>
<tr>
<td>[abc]</td>
<td>Set definition, can match the letter a or b or c</td>
</tr>
<tr>
<td>[abc[vz]]</td>
<td>Set definition, can match a or b or c followed by either v   or z</td>
</tr>
<tr>
<td>[^abc]</td>
<td>When a &#8220;^&#8221; appears as the first character inside   [] when it negates the pattern. This can match any character except a or b or   c</td>
</tr>
<tr>
<td>[a-d1-7]</td>
<td>Ranges, letter between a and d and figures from 1 to 7,   will not match d1</td>
</tr>
<tr>
<td>X|Z</td>
<td>Finds X or Z</td>
</tr>
<tr>
<td>XZ</td>
<td>Finds X directly followed by Z</td>
</tr>
<tr>
<td>$</td>
<td>Checks if a line end follows</td>
</tr>
</tbody>
</table>
<h3>2. Metacharacters</h3>
<p>The following meta characters have a pre-defined meaning and make certain common pattern easier to use, e.g. \d instead of [0...9].</p>
<p><strong>Table 2. </strong></p>
<table border="1" cellpadding="0">
<thead>
<tr>
<td><strong>Regular Expression</strong></td>
<td><strong>Description</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>\d</td>
<td>Any digit, short for [0-9]</td>
</tr>
<tr>
<td>\D</td>
<td>A non-digit, short for [^0-9]</td>
</tr>
<tr>
<td>\s</td>
<td>A whitespace character, short for [ \t\n\x0b\r\f]</td>
</tr>
<tr>
<td>\S</td>
<td>A non-whitespace character, for short for [^\s]</td>
</tr>
<tr>
<td>\w</td>
<td>A word character, short for [a-zA-Z_0-9]</td>
</tr>
<tr>
<td>\W</td>
<td>A non-word character [^\w]</td>
</tr>
<tr>
<td>\S+</td>
<td>Several non-whitespace characters</td>
</tr>
</tbody>
</table>
<h3>3. Quantifier</h3>
<p>A quantifier defines how often an element can occur. The symbols ?, *, + and {} define the quantity of the regular expressions</p>
<p><strong>Table 3. </strong></p>
<table border="1" cellpadding="0">
<thead>
<tr>
<td><strong>Regular Expression</strong></td>
<td><strong>Description</strong></td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>*</td>
<td>Occurs zero or more times</td>
<td></td>
</tr>
<tr>
<td>+</td>
<td>Occurs one or more times</td>
<td></td>
</tr>
<tr>
<td>?</td>
<td>Occurs no or one times, ? is short for {0,1}</td>
<td></td>
</tr>
<tr>
<td>{X}</td>
<td>Occurs X number of times, {} describes the order of the   preceding liberal</td>
<td></td>
</tr>
<tr>
<td>{X,Y}</td>
<td>.Occurs between X and Y times,</td>
<td></td>
</tr>
<tr>
<td>*?</td>
<td>? after a qualifier makes it a &#8220;reluctant   quantifier&#8221;, it tries to find the smallest match.</td>
<td></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=160&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/04/17/160/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>Pattern class of Regular Expression in Java</title>
		<link>http://metoojava.wordpress.com/2010/04/17/pattern-class-in-regular-expression/</link>
		<comments>http://metoojava.wordpress.com/2010/04/17/pattern-class-in-regular-expression/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 11:48:35 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mail ID validation]]></category>
		<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[Compile]]></category>
		<category><![CDATA[Java regular expression]]></category>
		<category><![CDATA[mail id validation using regular expression]]></category>
		<category><![CDATA[mail validation using regular expression]]></category>
		<category><![CDATA[Matcher]]></category>
		<category><![CDATA[matcher class in regular expression]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[Pattern class in jRegular expression]]></category>
		<category><![CDATA[refular expression in java]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=129</guid>
		<description><![CDATA[Introduction: This article makes you bit more knowledge in java regular expressions. For manage the regular expressions, the java have the three classes in java.util.regex package. But in this article we focused only Pattern class. A regular expression is a pattern of characters that describes a set of strings. We use the regular expressions to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=129&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:</strong></p>
<p>This article makes you bit more knowledge in java regular expressions. For manage the regular expressions, the java have the three classes in java.util.regex package. But in this article we focused only Pattern class.</p>
<p>A regular expression is a pattern of characters that describes a set of strings. We use the regular expressions to find, display, or modify some or all of the occurrences of a pattern in an input sequence.</p>
<p><strong>Java.util.regex classes:</strong></p>
<p><strong> </strong></p>
<p>The package java.util.regex contains three classes such as,</p>
<ul>
<li> <strong>Pattern Class</strong></li>
<li><strong>Matcher Class</strong></li>
<li> <strong>PatternSyntaxExcpetion</strong></li>
</ul>
<p><strong> Let us take a look at Pattern class.</strong></p>
<p><strong>Pattern Class:</strong></p>
<p><strong> </strong>A regular expression which is specified as a string that should be first compiled into an instance of<strong> <span style="color:#ff0000;"><code>Pattern</code></span></strong><strong> </strong>class. The resulting pattern can be used to create an instance of <strong> <span style="color:#ff0000;"><code>Matcher</code></span></strong> class which contains various in-built methods that helps in performing a match against the regular expression. Many <code>Matcher</code> objects can share the same <code>Pattern</code> object.</p>
<p><strong>Create Pattern using compile():</strong></p>
<p><strong> </strong>Pattern class doesn&#8217;t have a public constructor. So by using the static method <strong><span style="color:#ff0000;">compile</span></strong> we can create the pattern.</p>
<p><pre class="brush: css;">Pattern p = Pattern.compile(&quot;my regexp&quot;);</pre></p>
<p>For Regular expression symbols,click<a title="Regular Expression Symbols" href="http://metoojava.wordpress.com/?p=160&amp;preview=true" target="_blank"> <strong><em><span style="color:#0000ff;">here</span></em></strong></a></p>
<p><strong> </strong></p>
<p><strong>Important Note:</strong></p>
<p>The backslash is an escape character in Java Strings. i.e., backslash has a predefine meaning in Java. You have to use &#8220;\\&#8221; instead of “\”.</p>
<p>If you want to define &#8220;\w&#8221; then you must be using &#8220;\\w&#8221; in your regex like this.</p>
<p><pre class="brush: css;">Pattern r = Pattern.compile(“\\w+”); //Place your pattern here</pre></p>
<p>“\w“ represents a word character, i.e., short for [a-zA-Z_0-9]</p>
<p>We can create the Pattern with flags.</p>
<p><strong>Syntax:</strong></p>
<p><pre class="brush: css;">Pattern pattern=Pattern.compile(regex,flags);</pre></p>
<p>For ex, If we want to neglect the case sensitive we can achieve by using below one,</p>
<p><pre class="brush: css;">Pattern pattern = Pattern.compile(“\\w+”,Pattern.CASE_INSENSITIVE);</pre></p>
<p><strong> </strong></p>
<h3><strong>Validate pattern using matches():</strong></h3>
<p>The <span style="color:#ff0000;"><strong>matches()</strong> </span>method is used to check whether the given input is match with the pattern. This method returns true only if the entire input text matches the pattern.</p>
<p><pre class="brush: css;">boolean isMatch = Pattern.matches(“\\w+”,”Welcome to java world”);</pre></p>
<h3>Get the Pattern using pattern():</h3>
<p>The pattern() method is used for find out the pattern of the given string. This method returns the regular expression as a string from which this pattern was compiled.</p>
<p><pre class="brush: css;">Pattern p=input.pattern();</pre></p>
<h3>Split input using split():</h3>
<p>The split() method is used to split the given input text based on the given pattern. It returns a String array. There are two forms of <code>split()</code> method,</p>
<ul>
<li>split(String input)</li>
<li>split(String input, int      limit)</li>
</ul>
<p>In the second form, we have an argument called <code>limit</code> which is used to specify the limit i.e. the number of resultant strings that have to be obtained by <code>split()</code> method.</p>
<p><pre class="brush: css;">String[] str = pattern.split(input,3);
</pre></p>
<h3><code>Sample code for Pattern class and methods:</code></h3>
<h3><code>MailID Validation.java:</code></h3>
<p><pre class="brush: css;">import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Home
 */
class MailIDValidation
{
 public static void main(String args[])
 {
 //Input the string for validation
 String email = &quot;mymail@gmail.com&quot;;

 //Set the email pattern string
 Pattern p = Pattern.compile(&quot;.+@.+\\.[a-z]+&quot;);

 //Match the given string with the pattern
 Matcher m = p.matcher(email);

 //check whether match is found
 boolean matchFound = m.matches();

 if (matchFound)
 System.out.println(&quot;Valid Email Id.&quot;);
 else
 System.out.println(&quot;Invalid Email Id.&quot;);
 }
}
</pre></p>
<p><code> </code><strong> </strong></p>
<h3><strong><code>I hope it offer bit more knowledge in Regular Expressions. The next article makes you clear in Matcher class in regular expression.Please leave your footprints (comments) here.</code></strong></h3>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=129&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/04/17/pattern-class-in-regular-expression/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
		<item>
		<title>10 Fixes that solve IE Issues</title>
		<link>http://metoojava.wordpress.com/2010/04/03/10-fixes-that-solve-ie-issues/</link>
		<comments>http://metoojava.wordpress.com/2010/04/03/10-fixes-that-solve-ie-issues/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 04:45:06 +0000</pubDate>
		<dc:creator>metoojava</dc:creator>
				<category><![CDATA[ie]]></category>
		<category><![CDATA[ie fix]]></category>
		<category><![CDATA[ie issues]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css issues]]></category>
		<category><![CDATA[css with class]]></category>
		<category><![CDATA[css with id]]></category>
		<category><![CDATA[display:inline]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[How to solve ie bugs]]></category>
		<category><![CDATA[how to solve ie problems]]></category>
		<category><![CDATA[how to write css with id and class]]></category>
		<category><![CDATA[ID]]></category>
		<category><![CDATA[id and calss together]]></category>
		<category><![CDATA[ie bugs]]></category>
		<category><![CDATA[ie fixes]]></category>
		<category><![CDATA[ie invisible bugs]]></category>
		<category><![CDATA[ie problem]]></category>
		<category><![CDATA[ie solution]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[problem with css]]></category>

		<guid isPermaLink="false">http://metoojava.wordpress.com/?p=99</guid>
		<description><![CDATA[Introduction: Whenever i designed my web page i have found out some issues that issues make my design is  not compatible with a wide range of browsers.So in this article i add some tips for making your website compatible with a wide range of browsers . 1. Solve invisibility problems: If you face any problems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=99&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:</strong></p>
<p>Whenever i designed my web page i have found out some issues that issues make my design is  not compatible with a wide range of browsers.So in this article i add some tips for making your website compatible with a wide range of browsers .</p>
<p><strong> </strong></p>
<p><strong>1. Solve invisibility problems:</strong></p>
<p>If you face any problems like the image,text component are invisible sometimes, you add the property <strong><span style="color:#ff0000;">position:relative</span></strong> for the components to avoid the invisibility problems.<strong><br />
</strong></p>
<p><strong>2. Use display: inline for floated elements</strong></p>
<p>Floated elements with a margin can fire the famous IE6 double-margin bug, e.g. you specify a left margin of 5px and actually get 10px.<span style="color:#ff0000;"> <strong>Display:inline</strong></span> will fix the problem and, although it should not be required, your CSS remains valid.</p>
<p><strong>3.  Alternative for colon in components ID:<br />
</strong></p>
<p>The IE does not support colon for represents the components ID.If you want to refer the components ID which has colon you</p>
<p><pre class="brush: plain;">replace the colon with the value &#92;&#48;03A</pre></p>
<p>For ex,</p>
<p><pre class="brush: css;">&lt;h1 id=&quot;formID:titleID&quot;&gt;Welcome to My world&lt;/h1&gt;</pre></p>
<p>Css for Mozilla:</p>
<p><pre class="brush: css;">h1#formID:titleID
{
//some properties
}</pre></p>
<p>For IE:</p>
<p><pre class="brush: css;">h1#formID&#92;&#48;003AtitleID
{
//Some properties
}</pre></p>
<p><strong>4. Internet Explorer hacks</strong></p>
<p>While conditional comments are better, you can also target some versions of Internet Explorer using the following syntax:</p>
<p><pre class="brush: css;">body
{
Width: 200px; /* All browsers */
*width: 250px; /* IE */
_width:300px; /* IE6 */
.width:200px; /* IE7 */
}</pre></p>
<p>This technique is not W3C compliant (this is why you should use conditional comments instead) but sometimes, it is a real time saver.</p>
<p><strong>5. Avoid percentage dimensions</strong></p>
<p>Percentages confuse IE. Unless you can carefully size every parent element, they are probably best avoided. You can still use percentage values in other browsers with !important, e.g.</p>
<p style="text-align:left;">
<p><pre class="brush: css;">Body
{
height: 2%; !important
height: 20px; /*IE6 only*/
}</pre></p>
<p><strong>6. Another box model hack alternative</strong><strong> </strong></p>
<p>Box model hack is used to fix a rendering problem in pre-IE 6 browsers on PC, where by the border and padding are <em>included</em> in the width of an element, as opposed to <em>added on</em>. Number of CSS-based solutions has been put forward to remedy this, so here&#8217;s another one which we really like:</p>
<p style="text-align:left;">
<p><pre class="brush: css;">padding: 2em;
border: 1em solid green;
width: 20em;
width/**/:/**/ 14em;</pre></p>
<p>The first width command is read by all browsers; the second by all browsers <em>except</em> IE5.x on PC. Because the <strong>second command comes second it takes precedence over the first</strong> &#8211; any command that comes second will always override a preceding command. So, how does all this work?</p>
<p>By placing empty comment tags (/**/) before the colons, IE5.0 will ignore the command. Likewise, by placing these empty comment tags after the colon, IE5.5 will ignore the command. By using these two rules in conjunction with each other, we can hide the command from all of IE5.x.</p>
<p><strong>7.  Class</strong></p>
<p>The class selector allows you to set multiple styles to the same element or tag in a document. For example, you might want to have certain sections of your text called out in different colors from the rest of the text in the document. You would assign your paragraphs with classes like this:</p>
<p><pre class="brush: css;">P.blue
{
background-color: #0000ff;
}
P.red
{
background-color: #ff0000;
}</pre></p>
<p>Then, when you want to call the various classes you would use the CLASS attribute within the paragraph tag. Any tag that did not have a class attribute would be given the default style for that tag. For example:</p>
<p style="text-align:left;">
<p><pre class="brush: css;">&lt;p&gt;Welcome in blue background&lt;/p&gt;
&lt;p&gt;Hello world in red background&lt;/p&gt;</pre></p>
<p><strong>8. ID</strong></p>
<p>The ID selector allows you to give a name to a specific style without associating it with a tag or other HTML element. You write an ID code like this</p>
<p style="text-align:left;">
<p><pre class="brush: css;">h3#indent1 {text-indent: 10px ;}</pre></p>
<p>You associate an ID tag the same way you associate classes, within the element that should have that style:</p>
<p><pre class="brush: css;">&lt;h3 id=&quot;indent1&quot;&gt;This test for ID CSS&lt;/h3&gt;</pre></p>
<p>You can give your ID tags any grouping of letters and numbers that you would like.Keep in mind that <a href="http://www.w3.org/TR/REC-html40/struct/global.html">HTML standards</a> require that the ID must be unique.</p>
<p><strong>Note:</strong></p>
<p>One of the trickiest things about CSS is that it requires the use of formerly optional ending tags (as does XML). For example, if you have a style applied to a paragraph tag &lt;p&gt;, the browser may not know where to end that style if you do not include the ending tag &lt;/p&gt;.</p>
<p><strong>9.  Class and ID together</strong></p>
<p>If we need to assign the same style class or id we can assign different style for each one with using classes and ID together. For ex,</p>
<p style="text-align:left;">
<p><pre class="brush: css;">&lt;h1 id=&quot;blueheaderId&quot; class=&quot;blue&quot;&gt;Welcome to CSS&lt;/h1&gt;
h1#blueheaderId.blue {color: blue ;}</pre></p>
<p><strong>10. Refractor your code</strong></p>
<p style="text-align:left;">
<p style="text-align:left;">Often, it can take longer to fix than re-think a layout problem. Minor alterations to the HTML and simpler CSS are often more effective. This may mean you abandon perfectly legitimate code, but fewer long-term issues will arise and you know how to handle the problem in future.</p>
<p style="text-align:left;">Have I missed your favorites IE fix? Comments and suggestions welcome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/metoojava.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/metoojava.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/metoojava.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=metoojava.wordpress.com&amp;blog=12046599&amp;post=99&amp;subd=metoojava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://metoojava.wordpress.com/2010/04/03/10-fixes-that-solve-ie-issues/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/59743b7d5bce6e7c067f07cbb3c5478b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">metoojava</media:title>
		</media:content>
	</item>
	</channel>
</rss>
