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

<channel>
	<title>TechieDrill &#187; script</title>
	<atom:link href="http://techiedrill.com/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://techiedrill.com</link>
	<description>Your World Of Technical Tutorials</description>
	<lastBuildDate>Tue, 10 Aug 2010 20:39:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java ScriptEngineManager</title>
		<link>http://techiedrill.com/2009/11/java-scriptenginemanager/</link>
		<comments>http://techiedrill.com/2009/11/java-scriptenginemanager/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 07:39:07 +0000</pubDate>
		<dc:creator>karnamrajesh</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[manager]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://techiedrill.com/?p=448</guid>
		<description><![CDATA[ScriptEngineManager implements ScriptEngine classes. ScriptEngineManager holds key and value pair and stores the state of an object which is shared the engines created by the Manager. ScriptEngineManager uses the service provider technique to itemize implementations of ScriptEngineFactory.
Binding between the key and value pairs are traditionally referred to as the &#8220;Global Scope&#8221; that is available to [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ScriptEngineManager implements ScriptEngine classes. ScriptEngineManager holds key and value pair and stores the state of an object which is shared the engines created by the Manager. ScriptEngineManager uses the service provider technique to itemize implementations of ScriptEngineFactory.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Binding between the key and value pairs are traditionally referred to as the &#8220;Global Scope&#8221; that is available to all instances of ScriptEngine created by theScriptEngineManager. Value binded with the keys are made available to all the scripts.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ScriptEngineManager offers a method which returns arrays of these factories that includes few utilities on basis of mime type, languate name and file extensions.</div>
<p>ScriptEngineManager implements ScriptEngine classes. ScriptEngineManager holds key and value pair and stores the state of an object which is shared the engines created by the Manager. ScriptEngineManager uses the service provider technique to itemize implementations of ScriptEngineFactory.</p>
<p>Binding between the key and value pairs are traditionally referred to as the &#8220;Global Scope&#8221; that is available to all instances of ScriptEngine created by theScriptEngineManager. Value binded with the keys are made available to all the scripts.</p>
<p>ScriptEngineManager offers a method which returns arrays of these factories that includes few utilities on basis of mime type, languate name and file extensions.</p>
<p><em>import javax.script.*;</em></p>
<p><em>import java.io.*;</em></p>
<p><em>public class FileScript</em></p>
<p><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>public static void main(String args[])</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>ScriptEngineManager manager = new ScriptEngineManager();</em></p>
<p><span style="white-space:pre"><em> </em></span><em>ScriptEngine engine = manager.getEngineByName(&#8221;javascript&#8221;);</em></p>
<p><em><br />
</em></p>
<p><span style="white-space:pre"><em> </em></span><em>/*if(args.length!=1)</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.out.print(&#8221;Insufficient arguments&#8221;);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>System.exit(0);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}*/</em></p>
<p><em><br />
</em></p>
<p><span style="white-space:pre"><em> </em></span><em>FileReader reader = null;</em></p>
<p><span style="white-space:pre"><em> </em></span><em>try</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>reader = new FileReader(args[0]);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>catch(FileNotFoundException e1)</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>e1.printStackTrace();</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>try</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>engine.eval(reader);</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>catch(ScriptException e)</em></p>
<p><span style="white-space:pre"><em> </em></span><em>{</em></p>
<p><span style="white-space:pre"><em> </em></span><em>e.printStackTrace();</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><span style="white-space:pre"><em> </em></span><em>}</em></p>
<p><em>}</em></p>
<p><em>Note: Take the below code and save it as sample.js extension and run the above java code with the sample.js as run time argument for java interpreter </em></p>
<p><em><strong>Eg: java FileScript sample.js</strong></em></p>
<p><em>function hello()</p>
<p>{</p>
<p>println(&#8221;Hello from Function&#8221;);</p>
<p>}</p>
<p>for(i=0;i&lt;5;i++)</p>
<p>{</p>
<p><span style="white-space: pre;"> </span>print((i+1) + &#8221; &#8221; )</p>
<p><span style="white-space: pre;"> </span>hello()</p>
<p>}</p>
<p></em></p>
]]></content:encoded>
			<wfw:commentRss>http://techiedrill.com/2009/11/java-scriptenginemanager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
