<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ankit Virparia &#187; Java Bean</title>
	<atom:link href="http://ankit.co/category/tutorials/java-tutorials/java-bean/feed" rel="self" type="application/rss+xml" />
	<link>http://ankit.co</link>
	<description>A Programmer, Designer and Trainer</description>
	<lastBuildDate>Sun, 11 May 2014 04:15:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>How to retrieve Java Bean Metadata</title>
		<link>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-retrieve-java-bean-metadata</link>
		<comments>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata#comments</comments>
		<pubDate>Sat, 05 Jan 2013 11:37:55 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Java Bean]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[Java Bean Metadata]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=126</guid>
		<description><![CDATA[<p>Now, The question is How to retrieve the information about a given java bean class(I mean compiled class). That information is also known as Metadata: There are again 2 ways! And its based on how we have describe the Bean. As seen in previous tutorial &#8211; Link We have 2 methods to describe a Bean. [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata">How to retrieve Java Bean Metadata</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<ol>
Now, The question is How to retrieve the information about a given java bean class(I mean compiled class). That information is also known as Metadata:<br />
There are again 2 ways! And its based on how we have describe the Bean. As seen in previous tutorial &#8211; <a href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Link</a><br />
We have 2 methods to describe a Bean.</p>
<ol>
<li>Naming Conventions</li>
<li>By writing an additional class that extends the BeanInfo interface</li>
</ol>
<p><strong class="trheading">1. Naming Conventions</strong>.</p>
<pre class="brush: java; title: ; notranslate">
import java.beans.*;
public class EmpIntrospector 
{
	public static void main(String args[]) 
	{
		try 
		{
			Class c = Class.forName(&quot;Employee&quot;);
			BeanInfo beanInfo = Introspector.getBeanInfo(c);
			System.out.println(&quot;Properties:&quot;);
			PropertyDescriptor propertyDescriptor[] = beanInfo.getPropertyDescriptors();
			for(int i = 0; i &lt; propertyDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + propertyDescriptor[i].getName());
			}
			System.out.println(&quot;Events:&quot;);
			EventSetDescriptor eventSetDescriptor[] = beanInfo.getEventSetDescriptors();
			for(int i = 0; i &lt; eventSetDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + eventSetDescriptor[i].getName());
			}
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	}
}
</pre>
<p>In above sample code we are retrieving metadata by getting propertyDescriptor[] / eventDescriptopr[] using beanInfo Interface. </p>
<p><strong class="trheading">2. By writing an additional class that extends the BeanInfo interface</strong>.</p>
<pre class="brush: java; highlight: [11]; title: ; notranslate">
import java.beans.*;
public class EmpIntrospector2
{
	public static void main(String args[]) 
	{
		try 
		{
			Class c = Class.forName(&quot;Employee&quot;);
			BeanInfo beanInfo = Introspector.getBeanInfo(c);
			System.out.println(&quot;Properties:&quot;);
			PropertyDescriptor propertyDescriptor[] = new EmployeeBeanInfo().getPropertyDescriptors();
                        for(int i = 0; i &lt; propertyDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + propertyDescriptor[i].getName());
			}
			System.out.println(&quot;Events:&quot;);
			EventSetDescriptor eventSetDescriptor[] = new EmployeeBeanInfo().getEventDescriptors(); 
			for(int i = 0; i &lt; eventSetDescriptor.length; i++) 
			{
				System.out.println(&quot;\t&quot; + eventSetDescriptor[i].getName());
			}
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	}
}
</pre>
<p>In above sample code we are retrieving metadata by getting propertyDescriptor[] / eventDescriptopr[] using our defined class &#8220;EmployeeBeanInfo&#8221; which was describing Employee bean.</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata">How to retrieve Java Bean Metadata</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/java-bean/how-to-retrieve-java-bean-metadata/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Bean Introspection</title>
		<link>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-bean-introspection</link>
		<comments>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection#comments</comments>
		<pubDate>Sat, 05 Jan 2013 08:14:59 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Java Bean]]></category>
		<category><![CDATA[Introspection]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=103</guid>
		<description><![CDATA[<p>Introspection It is the self-examination of one&#8217;s conscious thoughts and feelings. [reference: Wikipedia] Java Bean Introspection It is the examination provided by a Java Bean class! But a class cannot speak. A developer has to write the description about the bean so that Other developers can understand the Bean properties/methods/events etc. In short, The process [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Java Bean Introspection</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><strong>Introspection</strong><br />
It is the self-examination of one&#8217;s conscious thoughts and feelings. [<strong>reference:</strong> <a href="http://en.wikipedia.org/wiki/Introspection">Wikipedia</a>]</p>
<p><strong>Java Bean Introspection</strong><br />
It is the examination provided by a Java Bean class! But a class cannot speak. A developer has to write the description about the bean so that Other developers can understand the Bean properties/methods/events etc.<br />
In short, The process to describe a Bean is known as Bean Introspection. </p>
<p><strong>Which is done by two ways:</strong></p>
<ol>
<li>Naming Conventions(What we did in previous tutorial &#8211; <a href="http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean">Link</a>)</li>
<li>By writing an additional class that extends the BeanInfo interface</li>
</ol>
<p><strong>In Brief:</strong><br />
<strong class="trheading">1. Naming Conventions</strong>.</p>
<ul>
<li><strong>Simple/Single Property: </strong>
<pre class="brush: java; title: ; notranslate">
    private int id;
    public void setId(int id) 
    {
        this.id = id;
    }

    public String getName() 
    {
        return name;
    }
</pre>
</li>
<li><strong>Indexed Property: </strong>
<pre class="brush: java; title: ; notranslate">
private double data[ ];
public double getData(int index) 
{
	return data[index];
}
public void setData(int index, double value) 
{
	data[index] = value;
}
public double[ ] getData( ) 
{
	return data;
}
public void setData(double[ ] values) 
{
	data = new double[values.length];
	System.arraycopy(values, 0, data, 0, values.length);
}
</pre>
</li>
<li><strong>Events: </strong>
<pre class="brush: java; title: ; notranslate">
public void addEventListener(EventListener e) 
{
	// code
}
public void removeEventListener(EventListener e) 
{
	// code
}
</pre>
</li>
</ul>
<p><strong class="trheading">2. By writing an additional class that extends the BeanInfo interface</strong></p>
<p>The BeanInfo interface enables us to explicitly control what information is available in a Bean. The BeanInfo interface defines following:</p>
<pre class="brush: java; title: ; notranslate">
PropertyDescriptor[ ] getPropertyDescriptors( )
EventSetDescriptor[ ] getEventSetDescriptors( )
MethodDescriptor[ ] getMethodDescriptors( )
</pre>
<p><strong>Now we are going to describe all the properties of Employee.class by using java.beans.SimpleBeanInfo(Derived from BeanInfo Interface):</strong></p>
<ul>
<li><strong>Property Descriptor: </strong>
<pre class="brush: java; title: ; notranslate">
import java.beans.SimpleBeanInfo;
public class EmployeeBeanInfo extends SimpleBeanInfo 
{
	public PropertyDescriptor[] getPropertyDescriptors() 
	{
		try 
		{
			PropertyDescriptor pdId = new PropertyDescriptor(&quot;id&quot;, Employee.class);
			PropertyDescriptor pdName = new PropertyDescriptor(&quot;name&quot;, Employee.class);
			PropertyDescriptor pdContact = new PropertyDescriptor(&quot;contact&quot;, Employee.class);
			PropertyDescriptor pd[] = {pdId, pdName, pdContact};
			return pd;
		}
		catch(Exception e) 
		{
			System.out.println(&quot;Exception caught. &quot; + e);
		}
	return null;
	}
}
</pre>
</li>
</ul>
<p>Same way we can describe Events and Methods of the Bean class.</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection">Java Bean Introspection</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/java-bean/java-bean-introspection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Java Bean</title>
		<link>http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introduction-to-java-bean</link>
		<comments>http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean#comments</comments>
		<pubDate>Fri, 04 Jan 2013 06:01:08 +0000</pubDate>
		<dc:creator><![CDATA[Ankit Virparia]]></dc:creator>
				<category><![CDATA[Java Bean]]></category>
		<category><![CDATA[Bean Standards]]></category>
		<category><![CDATA[conventions]]></category>

		<guid isPermaLink="false">http://ankit.co/?p=100</guid>
		<description><![CDATA[<p>What Is a Java Bean? Java bean is a reusable class which follows certain standards in terms of syntax. Mainly bean classes are used to encapsulate many data or objects inside one object. So that that single object can be sent/stored. A JavaBean is a Java Object which is serializable(So that we can send it [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean">Introduction to Java Bean</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>What Is a Java Bean?</h2>
<p>Java bean is a reusable class which follows certain standards in terms of syntax. Mainly bean classes are used to encapsulate many data or objects inside one object. So that that single object can be sent/stored. A JavaBean is a Java Object which is serializable(So that we can send it over network or store it in a File), has a pubilc 0-argument constructor(Default Constructor), private variables and public getter and setter methods.</p>
<p><strong>Advantages:</strong></p>
<ul>
<li>Write Once, Use it multiple times</li>
<li>Send multiple objects within 1 object</li>
<li>Java Bean provides Data sharing architecture so that a bean can be used to receive events from other objects.</li>
<li>Many frameworks understands Bean standards and take Bean class as input</li>
</ul>
<p><strong>JavaBean conventions:</strong></p>
<ul>
<li>public default constructor</li>
<li>Variables with access protection e.g private, protected, public, default</li>
<li>Public setter and getter for each variable to assign/access the values</li>
<li>Must implement serializable interface so that object can be sent/stored</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="brush: java; title: ; notranslate">
import java.io.Serializable;

public class Employee implements Serializable 
{
    private int id;
    private String name;
    private long contact;
    
    public Employee()
    {
        id = 0;
        name = &quot;&quot;;
        contact=0;        
    }

    public long getContact() {
        return contact;
    }

    public void setContact(long contact) {
        this.contact = contact;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
}
</pre>
<p>The post <a rel="nofollow" href="http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean">Introduction to Java Bean</a> appeared first on <a rel="nofollow" href="http://ankit.co">Ankit Virparia</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ankit.co/tutorials/java-tutorials/java-bean/introduction-to-java-bean/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
