<?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>Tech Manthan &#187; Java Manthan</title>
	<atom:link href="http://techmanthan.wordpress.com/category/java-manthan/feed/" rel="self" type="application/rss+xml" />
	<link>http://techmanthan.wordpress.com</link>
	<description>"Lets share knowledge..."</description>
	<lastBuildDate>Wed, 02 Jan 2008 06:37:41 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='techmanthan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/286b941bd3e6f31615e9e18190d2cc58?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Tech Manthan &#187; Java Manthan</title>
		<link>http://techmanthan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://techmanthan.wordpress.com/osd.xml" title="Tech Manthan" />
		<item>
		<title>Scripting In Java Platform</title>
		<link>http://techmanthan.wordpress.com/2008/01/02/scripting-in-java-platform/</link>
		<comments>http://techmanthan.wordpress.com/2008/01/02/scripting-in-java-platform/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 06:37:41 +0000</pubDate>
		<dc:creator>”દીપ”</dc:creator>
				<category><![CDATA[Java Manthan]]></category>

		<guid isPermaLink="false">http://techmanthan.wordpress.com/2008/01/02/scripting-in-java-platform/</guid>
		<description><![CDATA[Happy New Year to All 
One key feature of Java 6.0 is change in (Java Specification Request (JSR) 223), helps developers to integrate Java technology and scripting languages by defining a standard framework and application programming interface (API) to do the following:


    Access and control Java technology-based objects from a scripting environment 


    Create web content with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=31&subd=techmanthan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b><span style="font-size:10pt;font-family:Arial;">Happy New Year to All</span></b><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">One key feature of Java 6.0 is change in (Java Specification Request (JSR) 223), helps developers to integrate Java technology and scripting languages by defining a standard framework and application programming interface (API) to do the following:</span></p>
<ol>
<li>
<div><span style="font-size:10pt;font-family:Arial;"></span><font face="Times New Roman"><span style="font-size:10pt;"> </span></font><span style="font-size:10pt;color:black;"><font face="Times New Roman">   </font></span><span style="font-size:10pt;color:black;font-family:Arial;">Access and control Java technology-based objects from a scripting environment </span></div>
</li>
<li>
<div><span style="font-size:10pt;color:black;"><font face="Times New Roman">    </font></span><span style="font-size:10pt;color:black;font-family:Arial;">Create web content with scripting languages </span></div>
</li>
<li>
<div style="text-indent:-0.25in;line-height:15.6pt;text-align:justify;margin:0 0 0 0.25in;" class="MsoNormal"><span style="font-size:10pt;color:black;"><font face="Times New Roman">    </font></span><span style="font-size:10pt;color:black;font-family:Arial;">Embed scripting environments within Java technology-based applications </span></div>
</li>
</ol>
<p><span style="font-size:10pt;color:black;font-family:Arial;"></span><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;">This article focuses on the specification&#8217;s third goal and will show you how to use an embedded scripting environment from a Java platform application. A demo application called ScriptCalc will provide a working example of how to extend your applications with user-defined scripts in the JavaScript programming language. </span></font></p>
<p><font size="2" face="Arial"><span style="font-size:10pt;font-family:Arial;"></span></font><b><span style="font-size:10pt;color:black;font-family:Arial;">Basic Reasons to Use a Scripting Language</span></b></p>
<p><b><span style="font-size:10pt;color:black;font-family:Arial;"></span></b><span style="font-size:10pt;color:black;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;">Most scripting languages are dynamically typed. </span>You can usually create new variables without predetermining the variable type, and you can reuse variables to store values of different types. Also, scripting languages tend to perform many type conversions automatically, for example, converting the number 10 to the text &#8220;10&#8243; as necessary. Although some scripting languages are compiled, most languages are interpreted. Script environments generally perform the script compilation and execution within the same process. Usually, these environments also parse and compile scripts into intermediate code when they are first executed.</span><span style="font-size:10pt;font-family:Arial;">These qualities of scripting languages help you write applications faster, execute commands repeatedly, and tie together components from different technologies.</span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;">Combining scripting languages with the Java platform provides developers an opportunity to leverage the abilities of both environments. You can continue to use scripting languages for all the reasons you already have, and you can use the powerful Java class library to extend the abilities of those languages. If you are a Java language programmer, you now have the ability to ship applications that your customers can significantly and dynamically customize. The synergy between the Java platform and scripting languages produces an environment in which developers and end users can collaborate to create more useful, dynamic applications.</span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></span></p>
<p><b><span style="font-size:10pt;color:black;font-family:Arial;"></span></b><b><span style="font-size:10pt;color:black;font-family:Arial;">JSR 223 Implementation</p>
<p></span></b><span style="font-size:10pt;font-family:Arial;">Version 6 of the Java Platform, Standard Edition (Java SE), does not mandate any particular script engine, but it does include the Mozilla Rhino engine for the JavaScript programming language. The Java SE 6 platform implements the <span style="color:#666666;">java.script</span> APIs, which allow you to use script engines that comply with JSR 223. </span><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><b><span style="font-size:10pt;color:black;font-family:Arial;">Ways to Use the Scripting API</span></b></p>
<p><b><span style="font-size:10pt;color:black;font-family:Arial;"></span></b> <span style="font-size:10pt;font-family:Arial;">The scripting API is in the <span style="color:#666666;">javax.script</span> package available in the Java SE 6 platform. The API is still relatively small, composed of six interfaces and six classes, as Table 1 indicates.</span></p>
<table border="0" width="100%" cellPadding="0" cellSpacing="0" style="width:100%;" class="MsoNormalTable">
<tr>
<td colSpan="2" width="100%" vAlign="top" style="background:#999999;width:100%;border:#ece9d8;padding:0;">
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><b><span style="font-size:10pt;color:white;font-family:Arial;">Table 1: Interfaces and Classes in the Java SE 6 Platform</span></b></p>
</td>
</tr>
<tr>
<td colSpan="2" vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:black;font-family:Arial;"></p>
<table width="100%" cellPadding="0" cellSpacing="0">
<tr>
<td style="background-color:transparent;border:#ece9d8;">
<div></div>
</td>
</tr>
</table>
<p></span></td>
</tr>
<tr>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><b><span style="font-size:10pt;color:black;font-family:Arial;">Interface</span></b><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><b><span style="font-size:10pt;color:black;font-family:Arial;">Class</span></b><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">Bindings</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">AbstractScriptEngine</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">Compilable</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">CompiledScript</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">Invocable</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngineManager</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptContext</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">SimpleBindings</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngine</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background:#f1f1f1;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">SimpleScriptContext</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngineFactory</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
<td vAlign="top" style="background-color:transparent;border:#ece9d8;padding:0;"><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptException</span><span style="font-size:10pt;color:black;font-family:Arial;"></span></td>
</tr>
<tr>
<td colSpan="2" vAlign="top" style="background:#999999;border:#ece9d8;padding:0;"><b><span style="font-size:10pt;color:white;font-family:Arial;"></p>
<table width="100%" cellPadding="0" cellSpacing="0">
<tr>
<td style="background-color:transparent;border:#ffffff;">
<div></div>
</td>
</tr>
</table>
<p></span></b></td>
</tr>
</table>
<p><span style="font-size:10pt;color:black;font-family:Arial;"> </span><span style="font-size:10pt;"></span><span style="font-size:10pt;font-family:Arial;">Your starting point should be the <span style="color:#666666;">ScriptEngineManager</span> class. A <span style="color:#666666;">ScriptEngineManager</span> object can tell you what script engines are available to the Java Runtime Environment (JRE). It can also provide <span style="color:#666666;">ScriptEngine</span> objects that interpret scripts written in a specific scripting language. The simplest way to use this API is to do the following:</span><span style="font-size:10pt;"></span><span style="font-size:10pt;"><font face="Times New Roman"> </font></span></p>
<ol>
<li>
<div><span style="font-size:10pt;color:black;font-family:Arial;">Create a </span><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngineManager</span><span style="font-size:10pt;color:black;font-family:Arial;"> object. </span></div>
</li>
<li>
<div><span style="font-size:10pt;color:black;font-family:Arial;"></span><span style="font-size:10pt;color:black;font-family:Arial;">Retrieve a </span><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngine</span><span style="font-size:10pt;color:black;font-family:Arial;"> object from the manager. </span></div>
</li>
<li>
<div style="text-indent:-0.25in;line-height:15.6pt;text-align:justify;margin:0 0 0 0.25in;" class="MsoNormal"><span style="font-size:10pt;color:black;font-family:Arial;">Evaluate a script using the </span><span style="font-size:10pt;color:#666666;font-family:Arial;">ScriptEngine</span><span style="font-size:10pt;color:black;font-family:Arial;"> object. </span></div>
</li>
</ol>
<p><span style="font-size:10pt;font-family:Arial;">That sounds easy enough, but what does the code look like? Above Example  performs all three steps, printing <span style="color:#666666;">Hello, world!</span> to the console.</span></p>
<p><b><span style="font-size:10pt;font-family:Arial;">Create a <span style="color:#666666;">ScriptEngine</span> object using the engine name.</span></b><span style="font-size:10pt;font-family:Arial;"></span></p>
<table border="0" width="100%" cellPadding="0" cellSpacing="0" style="background:#e7e7e7;width:100%;" class="MsoNormalTable">
<tr>
<td style="background:0 0;border:#ece9d8;padding:7.5pt;">
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>ScriptEngineManager mgr = new ScriptEngineManager();</span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>ScriptEngine jsEngine = mgr.getEngineByName(&#8220;JavaScript&#8221;);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>try {</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>    </span></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>          </span>jsEngine.eval(&#8220;print(&#8216;Hello, world!&#8217;)&#8221;);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span></span>  } catch (ScriptException ex) {</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span> </span>ex.printStackTrace();</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>}<span>    </span></span></p>
</td>
</tr>
</table>
<p><span style="font-size:10pt;font-family:Arial;">Below code shows how to evaluate a file that the customer has supplied. The file name is <span style="color:#666666;">/scripts/F1.js</span>, and it is located under the application directory.</span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span> <b><span style="font-size:10pt;font-family:Arial;">The <span style="color:#666666;">eval</span> method can read script files.</span></b><span style="font-size:10pt;font-family:Arial;"></span></p>
<table border="0" width="100%" cellPadding="0" cellSpacing="0" style="background:#e7e7e7;width:100%;" class="MsoNormalTable">
<tr>
<td style="background:0 0;border:#ece9d8;padding:7.5pt;">
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>ScriptEngineManager engineMgr = new ScriptEngineManager();</span></p>
<p><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>ScriptEngine engine = engineMgr.getEngineByName(&#8220;ECMAScript&#8221;);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span> </span></span></p>
<p><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>InputStream is = </span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>      </span>this.getClass().getResourceAsStream(&#8220;/scripts/F1.js&#8221;);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span> </span></span></p>
<p><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>try {</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>    </span>Reader reader = new InputStreamReader(is);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>    </span></span></p>
<p><span style="font-size:10pt;color:#666666;font-family:Arial;"><span></span> engine.eval(reader);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span></span></p>
<p><span style="font-size:10pt;color:#666666;font-family:Arial;"><span></span> } catch (ScriptException ex) {</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>    </span>ex.printStackTrace();</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>}</span></td>
</tr>
</table>
<p><span style="font-size:10pt;color:black;font-family:Arial;"><b> </b></span><span style="font-size:10pt;color:black;font-family:Arial;"><b>How to Invoke a Script Procedure</b><span style="font-size:10pt;color:black;font-family:Arial;"> </span></span><span style="font-size:10pt;color:black;font-family:Arial;"> </span></p>
<p><span style="font-size:10pt;color:black;font-family:Arial;"></span><span style="font-size:10pt;color:black;font-family:Arial;"><span style="font-size:10pt;color:black;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">Running entire scripts is useful, but you may want to invoke only specific script procedures. Some script engines implement the <span style="color:#666666;">Invocable</span> interface. If an engine implements this interface, you can call or invoke specific methods or functions that the engine has already evaluated. </span><span style="font-size:10pt;font-family:Arial;">Script engines are not required to support the <span style="color:#666666;">Invocable</span> interface. However, the Rhino JavaScript technology implementation in the Java SE 6 platform does. If your script contains a function called <span style="color:#666666;">sayHello</span>, you could invoke it repeatedly by casting your <span style="color:#666666;">ScriptEngine</span> object to an <span style="color:#666666;">Invocable</span> object and by calling its <span style="color:#666666;">invokeFunction</span> method. Alternatively, if your script defines objects, you can call object methods using the <span style="color:#666666;">invokeMethod</span> method. Code Example 7 demonstrates how to use this interface.</span></span><span style="font-size:10pt;color:black;font-family:Arial;"> </span><span style="font-size:10pt;color:black;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span><b><span style="font-size:10pt;font-family:Arial;">You can use the <span style="color:#666666;">Invocable</span> interface to call specific methods in a script.</span></b><span style="font-size:10pt;font-family:Arial;"></span></span></p>
<table border="0" width="100%" cellPadding="0" cellSpacing="0" style="background:#e7e7e7;width:100%;" class="MsoNormalTable">
<tr>
<td style="background:0 0;border:#ece9d8;padding:7.5pt;">
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>jsEngine.eval(&#8220;function sayHello() {&#8221; +</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>         </span>&#8220;<span>  </span>println(&#8216;Hello, world!&#8217;);&#8221; +</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>                </span>&#8220;}&#8221;);</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>Invocable invocableEngine = (Invocable) jsEngine;</span><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span></span></p>
<p style="line-height:15.6pt;text-align:justify;margin:0;" class="MsoNormal"><span style="font-size:10pt;color:#666666;font-family:Arial;"><span>  </span>invocableEngine.invokeFunction(&#8220;sayHello&#8221;);</span></p>
</td>
</tr>
</table>
<p><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-size:10pt;font-family:Arial;">Be aware that <span style="color:#666666;">invokeMethod</span> and <span style="color:#666666;">invokeFunction</span> methods can throw several exceptions, so you must be prepared to catch <span style="color:#666666;">ScriptException</span>, <span style="color:#666666;">NoSuchMethodException</span>, and perhaps even <span style="color:#666666;">NullPointerException</span> exceptions.</span></p>
<p><span style="font-size:10pt;font-family:Arial;">More Information : http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/</span><span style="font-size:10pt;"><font face="Times New Roman"> </font></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techmanthan.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techmanthan.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techmanthan.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techmanthan.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techmanthan.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techmanthan.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techmanthan.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techmanthan.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techmanthan.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techmanthan.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techmanthan.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techmanthan.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=31&subd=techmanthan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://techmanthan.wordpress.com/2008/01/02/scripting-in-java-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e8f639828480140d127e55a64df57538?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">”દીપ”</media:title>
		</media:content>
	</item>
		<item>
		<title>JAVA DESING PATTERNS &#8211; I</title>
		<link>http://techmanthan.wordpress.com/2007/05/14/java-desing-patterns-i/</link>
		<comments>http://techmanthan.wordpress.com/2007/05/14/java-desing-patterns-i/#comments</comments>
		<pubDate>Mon, 14 May 2007 05:26:12 +0000</pubDate>
		<dc:creator>”દીપ”</dc:creator>
				<category><![CDATA[Java Manthan]]></category>

		<guid isPermaLink="false">http://techmanthan.wordpress.com/2007/05/14/java-desing-patterns-i/</guid>
		<description><![CDATA[JAVA DESIGN PATTERN (PART-I)
                                                    [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=20&subd=techmanthan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h1><span style="font-family:Verdana;">JAVA DESIGN PATTERN (PART-I)</span></h1>
<p><strong><span style="font-size:14pt;font-family:Verdana;">                                                                By Deepak Parmar</font></span></strong></p>
<p><strong><span style="font-size:14pt;font-family:Verdana;"><strong><span style="font-family:Arial;"></span></strong><strong><span style="font-family:Arial;"></span></strong></span></strong><strong><span style="font-size:14pt;font-family:Verdana;"></span></strong><strong><span style="font-size:14pt;font-family:Verdana;"></span></strong><span style="font-size:10pt;font-family:Arial;">“Pattern” as the name suggests, means series of events occurring in a definite order. The patterns can be found in Java and J2ee technologies also. Many a times, we find that there is a particular way of tackling a problem. This way is easy and has been used many times successfully by a number of people earlier also. This method becomes a pattern.</span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span><strong><span style="font-size:10pt;font-family:Arial;">Patterns Defined:</span></strong><span style="font-size:10pt;font-family:Arial;"> The patterns can be defined in many ways. You can find the definitions of patterns in many good books.</span></p>
<p><em><strong><span style="font-size:10pt;font-family:Arial;">&#8220;Design patterns are recurring solutions to design problems.&#8221;</span></strong></em></p>
<p><strong><span style="font-size:10pt;font-family:Arial;">Patterns:</span></strong><span style="font-size:10pt;font-family:Arial;"> According to commonly known practices, there are 23 design patterns in Java. These patterns are grouped under three heads:</span><span style="font-size:10pt;font-family:Arial;"><br />
</span><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p><span style="font-size:10pt;font-family:Arial;">1. Creational Patterns</span><span style="font-size:10pt;font-family:Arial;"> </span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;">2. Structural Patterns</span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;">3. Behavioral Patterns</span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><strong><span style="font-family:Verdana;">Creational Patterns &#8211; Factory Pattern</span></strong></span><span style="font-size:10pt;font-family:Arial;"> </span></span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;">Factory of what? Of classes. In simple words, if we have a super class and n sub-classes, and based on data provided, we have to return the object of one of the sub-classes, we use a factory pattern.Let’s take an example to understand this pattern.</span></span></span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span></span></span></p>
<p><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span><span style="font-size:10pt;font-family:Arial;"> </span></span></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span></span><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"><span style="font-family:Arial;"></span><strong><span style="font-size:10pt;font-family:Arial;">Example:</span></strong><span style="font-size:10pt;font-family:Arial;"> Let’s suppose an application asks for entering the name and sex of a person. If the sex is Male (M), it displays welcome message saying Hello Mr. &lt;Name&gt; and if the sex is Female (F), it displays message saying Hello Ms &lt;Name&gt;.</span><span style="font-size:10pt;font-family:Arial;">The skeleton of the code can be given here.<span style="font-family:Arial;"></span></span></span></span></span></p>
<table style="width:100%;" class="MsoNormalTable" border="0" cellpadding="0" width="100%">
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">public class Person {</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td style="border:medium none #ece9d8;width:10%;background-color:transparent;padding:0.75pt;" width="10%"><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-family:Arial;"></span></td>
<td style="border:medium none #ece9d8;width:90%;background-color:transparent;padding:0.75pt;" width="90%"><span style="font-size:10pt;font-family:Arial;">// name string<br />
public String name;<br />
// gender : M or F<br />
private String gender; </span><span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">public String getName() {<br />
return name;<br />
}public String getGender() {<br />
return gender;<br />
}<span style="font-family:Arial;"></span></span></td>
</tr>
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">}// End of class</span><span style="font-family:Arial;"></span></td>
</tr>
</table>
<p><span style="font-size:10pt;font-family:Arial;">This is a simple class Person having methods for name and gender. Now, we will have two sub-classes, Male and Female which will print the welcome message on the screen.</span><span style="font-family:Arial;"></span></p>
<table style="width:100%;" class="MsoNormalTable" border="0" cellpadding="0" width="100%">
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">public class Male extends Person {</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td style="border:medium none #ece9d8;width:10%;background-color:transparent;padding:0.75pt;" width="10%"><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-family:Arial;"></span></td>
<td style="border:medium none #ece9d8;width:90%;background-color:transparent;padding:0.75pt;" width="90%"><span style="font-size:10pt;font-family:Arial;">public Male(String fullName) {<br />
System.out.println(&#8220;Hello Mr. &#8220;+fullName);<br />
}</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">}// End of class</span><span style="font-family:Arial;"></span></td>
</tr>
</table>
<p><span style="font-family:Arial;"></span><span style="font-family:Arial;"><span style="font-size:10pt;font-family:Arial;">Also, the class Female</span><span style="font-family:Arial;"></span></span></p>
<table style="width:100%;" class="MsoNormalTable" border="0" cellpadding="0" width="100%">
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">public class Female extends Person {</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td style="border:medium none #ece9d8;width:10%;background-color:transparent;padding:0.75pt;" width="10%"><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-family:Arial;"></span></td>
<td style="border:medium none #ece9d8;width:90%;background-color:transparent;padding:0.75pt;" width="90%"><span style="font-size:10pt;font-family:Arial;">public Female(String fullNname) {<br />
System.out.println(&#8220;Hello Ms. &#8220;+fullNname);<br />
}</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">}// End of class</span><span style="font-family:Arial;"></span></td>
</tr>
</table>
<p><span style="font-size:10pt;font-family:Arial;">Now, we have to create a client, or a SalutationFactory which will return the welcome message depending on the data provided. </span><span style="font-family:Arial;"></span></p>
<table style="width:100%;" class="MsoNormalTable" border="0" cellpadding="0" width="100%">
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">public class SalutationFactory {</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td style="border:medium none #ece9d8;width:10%;background-color:transparent;padding:0.75pt;" width="10%"><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-family:Arial;"></span></td>
<td style="border:medium none #ece9d8;width:90%;background-color:transparent;padding:0.75pt;" width="90%"><span style="font-size:10pt;font-family:Arial;">public static void main(String args[]) {<br />
SalutationFactory factory = new SalutationFactory();<br />
factory.getPerson(args[0], args[1]);<br />
}</span><span style="font-family:Arial;"><font size="3"> </font></span><span style="font-size:10pt;font-family:Arial;">public Person getPerson(String name, String gender) {<br />
if (gender.equals(&#8220;M&#8221;))<br />
return new Male(name);<br />
else if(gender.equals(&#8220;F&#8221;))<br />
return new Female(name);<br />
else<br />
return null;<br />
}</span><span style="font-family:Arial;"></span></td>
</tr>
<tr>
<td colspan="2" style="border:medium none #ece9d8;background-color:transparent;padding:0.75pt;"><span style="font-size:10pt;font-family:Arial;">}// End of class</span><span style="font-family:Arial;"></span></td>
</tr>
</table>
<p><span style="font-size:10pt;font-family:Arial;">This class accepts two arguments from the system at runtime and prints the names. </span><span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">Running the program:</span><span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">After compiling and running the code on my computer with the arguments Prashant and M:</span><span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">java Prashant M</span><span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;">The result returned is: “Hello Mr. Prashant”.</span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span><span style="font-family:Arial;"></span><strong><span style="font-size:10pt;font-family:Arial;">When to use a Factory Pattern?</span></strong></p>
<p><strong><span style="font-size:10pt;font-family:Arial;"></span></strong><span style="font-size:10pt;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"> </span><span style="font-size:10pt;font-family:Arial;">1. When a class does not know which class of objects it must create.<br />
2. A class specifies its sub-classes to specify which objects to create.<br />
3. In programmer’s language (very raw form), you can use factory pattern where you have to create an object of any one of sub-classes depending on the data provided.<span style="font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"> </span></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techmanthan.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techmanthan.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techmanthan.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techmanthan.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techmanthan.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techmanthan.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techmanthan.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techmanthan.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techmanthan.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techmanthan.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techmanthan.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techmanthan.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=20&subd=techmanthan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://techmanthan.wordpress.com/2007/05/14/java-desing-patterns-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e8f639828480140d127e55a64df57538?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">”દીપ”</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate &#8211; An Object Relational Mapping (ORM) solution</title>
		<link>http://techmanthan.wordpress.com/2007/04/30/hibernate/</link>
		<comments>http://techmanthan.wordpress.com/2007/04/30/hibernate/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 12:02:20 +0000</pubDate>
		<dc:creator>sandipdavda</dc:creator>
				<category><![CDATA[Java Manthan]]></category>

		<guid isPermaLink="false">http://techmanthan.wordpress.com/2007/04/30/hibernate/</guid>
		<description><![CDATA[Hibernate 
By Anju Ravindran
Hibernate is an object-relational mapping (ORM) solution for the Java language. It is free as open source software that is distributed under the GNU Lesser General Public License. It provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. The purpose of Hibernate is to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=7&subd=techmanthan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p align="center"><strong><font color="#993366" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;color:#993366;font-family:Arial;"><span style="font-size:14pt;font-family:Verdana;"><font color="#000000">Hibernate </font></span></span></font></strong></p>
<p align="right"><strong><font color="#993366" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;color:#993366;font-family:Arial;"><span style="font-size:10pt;font-family:Arial;"><u><font color="#000000">By Anju Ravindran</font></u></span></span></font></strong></p>
<p align="justify"><strong><font color="#993366" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;color:#993366;font-family:Arial;">Hibernate</span></font></strong><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"> is an object-relational mapping (ORM) solution for the Java language. It is free as open source software that is distributed under the GNU Lesser General Public License. It provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database.</span></font><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"> </span></font><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;">The purpose of Hibernate is to relieve the developer from a significant amount of <span style="font-weight:bold;">common data persistence-related programming tasks</span>. Hibernate adapts to the developer&#8217;s development process, whether starting from scratch or from a legacy database. The main disadvantages of java CMP entity beans include:</span></font><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"> </span></font></span></font></p>
<ul>
<li class="MsoNormal"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;">CMP entity beans are slow </span></font></li>
<li class="MsoNormal"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;">They must reside inside some Application Server </span></font></li>
<li class="MsoNormal"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;">They require special method names. </span></font></li>
<li class="MsoNormal"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;">They are not serializable</span></font></li>
</ul>
<p align="justify"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"></span></font><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;">Hibernate not only takes care of the mapping from Java classes to database tables</span> (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. Hibernate generates the SQL calls and relieves the developer from manual result set handling and object conversion, keeping the application portable to all SQL databases.<font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"> </span></font></font></span><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;">Hibernate provides transparent persistence for &#8220;Plain Old Java Objects&#8221;; the only strict requirement for a persistent class is a no-argument constructor, not compulsorily public. Hibernate is typically used both in standalone Java applications</span> and in Java EE applications using servlets or EJB session beans.</font></span><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"> </span></font></font></font></p>
<p><font color="#000000" face="Arial" size="2"><font color="#000000" face="Arial" size="2"><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"></span></font><font color="#000000" face="Arial" size="2"><span style="font-size:10pt;color:#000000;font-family:Arial;"><strong><font color="#000000" face="Arial" size="2"><br />
<span style="font-size:10pt;color:#000000;font-family:Arial;">Hibernate Core for Java key features:</span></font></strong></span></font></font></font><font color="#000000" face="Arial" size="2"> </font></p>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">Natural programming model</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate supports natural OO idiom; inheritance, polymorphism, composition and the Java collections framework</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">Support for fine-grained object models</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; a rich variety of mappings for collections and dependent objects</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">No build-time byte code enhancement</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; there&#8217;s no extra code generation or bytecode processing steps in your build procedure</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">Extreme scalability</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate is extremely performant, has a dual-layer cache architecture, and may be used in a cluster</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">The query options</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate addresses both sides of the problem; not only how to get objects into the database, but also how to get them out again</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">Support for &#8220;conversations&#8221;</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate supports both long-lived persistence contexts, detach/reattach of objects, and takes care of optimistic locking automatically</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">Free/open source</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate is licensed under the LGPL (Lesser GNU Public License)</span></font></p>
</li>
<p></font></ul>
<ul> <font color="#000000" face="Arial" size="2"></p>
<li class="MsoNormal">
<p align="justify"><strong><font color="#000000" face="Arial" size="2"><span style="font-weight:bold;font-size:10pt;font-family:Arial;">EJB 3.0</span></font></strong><font face="Arial" size="2"><span style="font-size:10pt;font-family:Arial;"> &#8211; Hibernate implements the <a href="http://jpa.hibernate.org/" title="http://jpa.hibernate.org/">Java Persistence</a> management API and object/relational mapping options, two members of the Hibernate team are active in the expert group</span></font></p>
</li>
<p></font></ul>
<p><font color="#000000" face="Arial" size="2"><font color="#993366" face="Arial" size="2"><span style="font-size:10pt;color:#993366;font-family:Arial;"></span></font></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techmanthan.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techmanthan.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techmanthan.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techmanthan.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techmanthan.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techmanthan.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techmanthan.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techmanthan.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techmanthan.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techmanthan.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techmanthan.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techmanthan.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=7&subd=techmanthan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://techmanthan.wordpress.com/2007/04/30/hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5f019e0ba792084a81a84fae9f55f1a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sandip Davda</media:title>
		</media:content>
	</item>
		<item>
		<title>JAVAP &#8211; Hidden Fact Behind Java Programs</title>
		<link>http://techmanthan.wordpress.com/2007/04/30/hello-world/</link>
		<comments>http://techmanthan.wordpress.com/2007/04/30/hello-world/#comments</comments>
		<pubDate>Mon, 30 Apr 2007 05:01:30 +0000</pubDate>
		<dc:creator>sandipdavda</dc:creator>
				<category><![CDATA[Java Manthan]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[JAVAP &#8211; Do u know this?  
By: Sandip Davda
When compiling programs in Java, it is well known that the code is not compiled to machine code. Programs in Java are compiled to into an intermediate bytecode format that is executed by a Java Virtual Machine. Most developers although have never seen byte code. (nor have many [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=1&subd=techmanthan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p align="center"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:14pt;color:#993366;font-family:Arial;"><span><font color="#000000"><strong>JAVAP &#8211; Do u know this?</strong> </font></span></span><span style="font-size:10pt;color:#993366;font-family:Arial;"> </span></span></p>
<p align="right"><span style="font-size:10pt;font-family:Arial;"><span style="font-size:10pt;color:#993366;font-family:Arial;"></span><strong><u><span style="font-size:10pt;font-family:Arial;">By: Sandip Davda</span></u></strong></span></p>
<p align="justify"><span style="font-size:10pt;font-family:Arial;"><strong><u><span style="font-size:10pt;font-family:Arial;"></span></u></strong><strong><u><span style="font-family:Georgia;"></span></u></strong></span><span style="font-size:10pt;font-family:Arial;">When compiling programs in Java, it is well known that the code is not compiled to machine code. Programs in Java are compiled to into an intermediate bytecode format that is executed by a Java Virtual Machine. Most developers although have never seen byte code. (nor have many ever wanted to see it!) One way to view the byte code is to compile your class and then open the .class file in a hex editor and translate the bytecodes by referring to the virtual machine specification. A much easier way is to utilize the command-line utility <strong><span style="font-family:Arial;">javap</span></strong>. The Java SDK from Sun includes the <code><span style="font-family:Arial;">javap</span></code> disassembler, that will convert the byte codes into human-readable mnemonics.</span></p>
<pre><span style="font-size:10pt;color:blue;font-family:Arial;">public class JavapDemoApplication {<span>    </span></span><span style="font-size:10pt;font-family:Arial;"></span></pre>
<pre><span style="font-size:10pt;color:blue;font-family:Arial;"><span> </span>public static void main(String[] args) {<span>       </span></span><span style="font-size:10pt;font-family:Arial;"></span></pre>
<pre><span style="font-size:10pt;color:blue;font-family:Arial;"><span>  </span>System.out.println("javap Demo Application");<span>    </span></span><span style="font-size:10pt;font-family:Arial;"></span></pre>
<pre><span style="font-size:10pt;color:blue;font-family:Arial;"><span> </span>} }</span><span style="font-size:10pt;font-family:Arial;"></span></pre>
<p align="justify"><span style="font-size:10pt;font-family:Arial;">Using the &#8216;-c&#8217; option, you can get a bytecode listing from <code><span style="font-family:Arial;">javap</span></code> as follows:</span></p>
<p><span style="font-size:10pt;font-family:Arial;"></span><span style="font-size:10pt;font-family:Arial;"></p>
<p align="center" style="line-height:15.6pt;text-align:center;margin:0;" class="MsoNormal"> </p>
<hr SIZE="2" width="250" align="center" /></span></p>
<pre><span style="font-size:10pt;font-family:Arial;">% <strong><span style="font-family:Arial;">javac JavapDemoApplication.java</span></strong></span></pre>
<pre><span style="font-size:10pt;font-family:Arial;">% <strong><span style="font-family:Arial;">javap -c JavapDemoApplication</span></strong></span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"> Compiled from JavapDemoApplication.java</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;">public class JavapDemoApplication</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"> extends java.lang.Object</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;">{<span>     </span>public JavapDemoApplication();</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>     </span>public static void main(java.lang.String[]);</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;">}</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"> Method JavapDemoApplication()</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>0 aload_0 1 invokespecial #1 &lt;Method java.lang.Object()&gt;</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>4 return<span>  </span>Method void main(java.lang.String[])</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>0 getstatic #2 &lt;Field java.io.PrintStream out&gt;</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>3 ldc #3 &lt;String "javap Demo Application"&gt;</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>5 invokevirtual #4 &lt;Method void println(java.lang.String)&gt;</span></pre>
<pre><span style="font-size:10pt;font-family:Arial;"><span>   </span>8 return</span></pre>
<p align="center" style="line-height:15.6pt;text-align:center;margin:0;" class="MsoNormal"><span style="font-size:10pt;font-family:Arial;"></p>
<hr SIZE="2" width="250" align="center" /></span></p>
<p><span style="font-size:10pt;font-family:Arial;">To gain a better understanding of byte code, lets start with the first instruction in the main method:</span></p>
<pre><span style="font-size:10pt;font-family:Arial;"><span>  </span>0 getstatic #2 &lt;Field java.io.PrintStream out&gt;</span></pre>
<p align="justify"><span style="font-size:10pt;font-family:Arial;">The initial integer is the offset of the instruction in the method. So the first instruction begins with a &#8216;0&#8242;. The mnemonic for the instruction follows the offset. In this example, the &#8216;<code><span style="font-family:Arial;">getstatic</span></code>&#8216; instruction pushes a static field onto a data structure called the <em><span style="font-family:Arial;">operand stack</span></em>. Later instructions can reference the field in this data structure. Following the <code><span style="font-family:Arial;">getstatic</span></code> instruction is the field to be pushed. In this case the field to be pushed is &#8220;#2 &lt;Field java.io.PrintStream out&gt;.&#8221; If you examined the bytecode directly, you would see that the field information is not embedded directly in the instruction. Instead, like all constants used by a Java class, the field information is stored in a shared pool. Storing field information in a constant pool reduces the size of the bytecode instructions. This is because the instructions only have to store the integer index into the constant pool instead of the entire constant. In this example, the field information is at location #2 in the constant pool. The order of items in the constant pool is compiler dependent, so you might see a number other than &#8216;#2.&#8217;</span><span style="font-size:10pt;font-family:Arial;">After analyzing the first instruction, it&#8217;s easy to guess the meaning of the other instructions. The &#8216;<code><span style="font-family:Arial;">ldc</span></code>&#8216; <em><span style="font-family:Arial;">(load constant)</span></em> instruction pushes the constant &#8220;javap Demo Application&#8221; onto the operand stack. The &#8216;<code><span style="font-family:Arial;">invokevirtual</span></code>&#8216; invokes the println method, which pops its two arguments from the operand stack. Don&#8217;t forget that an instance method such as println has two arguments: the obvious string argument, plus the implicit &#8216;this&#8217; reference</span><strong><span style="font-size:10pt;font-family:Arial;"> </span></strong></p>
<p><strong><span style="font-size:10pt;font-family:Arial;"></span></strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techmanthan.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techmanthan.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techmanthan.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techmanthan.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techmanthan.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techmanthan.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techmanthan.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techmanthan.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techmanthan.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techmanthan.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techmanthan.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techmanthan.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techmanthan.wordpress.com&blog=1042563&post=1&subd=techmanthan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://techmanthan.wordpress.com/2007/04/30/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f5f019e0ba792084a81a84fae9f55f1a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Sandip Davda</media:title>
		</media:content>
	</item>
	</channel>
</rss>