Writing Java Script in Java.

A small code that can call JS code from within Java.
This feature is part of the jdk6 version.









01 import javax.script.\*;
02 import java.util.\*;
03
04 class Sample
05 {
06 public static void main(String[] args)
07 {
08
09 ScriptEngineManager manager= new ScriptEngineManager();
10 List<ScriptEngineFactory> factories= manager.getEngineFactories();
11
12 for (ScriptEngineFactory factory: factories) {
13
14 String name = factory.getEngineName();
15 String version = factory.getEngineVersion();
16 String language = factory.getLanguageName();
17
18 System.out.println(name+"("+version+"): "+language);
19
20 for(String n: factory.getNames())
21 System.out.println(n);
22 }
23
24 // JavaScript code in a String
25 String script = "function hello(name) { print('Hello, ' + name); }";
26
27
28 ScriptEngine engine = manager.getEngineByName("JavaScript");
29
30 try
31 {
32 // evaluate JavaScript code from String
33 engine.eval("print('Hello, World')");
34 engine.eval(script);
35 Invocable inv = (Invocableengine;
36 inv.invokeFunction("hello""THE");
37
38 }
39 catch (ScriptException e)
40 {
41 e.printStackTrace();
42 }
43 catch (NoSuchMethodException ee){
44 ee.printStackTrace();
45 }
46
47
48 }
49 }

Comments:

Good evening java scripting team and sun microsystems. When i visited your website i found it very good and easy approachable. I have only one question that how can i download JavaScript language on my computer. my computer does not has Java language. I shall be very thankful to you. please reply me through my e-mail.

Posted by uzair ahmed khan on January 30, 2009 at 10:43 AM IST #

@Ahmed :
JavaScript is default with browser. For Java you need to download jre from java.com. Please download these required things and run the apps.

Posted by Vaibhav Choudhary on February 06, 2009 at 01:51 AM IST #

Hello! This is uzair ahmed khan from wazirabad. I am the student of virtual university of Pakistan and need some help. My question is that i want to make a calculator using java language. I have used many codes but still not able to get the results. I have made all the buttons of calculator and the resulting screen, but unable to see the results. If you help me in this matter i shall be very thankful to you.

Posted by uzair ahmed khan on June 17, 2009 at 05:18 PM IST #

For further information about the Warhammer CD-key and Warhammer Timecard, Please keep an eye on air jordan shoes.
For more information please keep an eye on cheap jordan shoes .

Posted by michael jordan shoes on June 26, 2009 at 02:24 AM IST #

Your article very interesting, I have introduced a lot of friends look at this article, the content of the articles there will be a lot of attractive people to appreciate, I have to thank you such an article.

Posted by nike sb on July 08, 2009 at 01:57 AM IST #

I wonder if there is an underlying variable that affects both the dependence on trade and the social safety net. Perhaps some aspect of culture or geography might be responsible for both.

Posted by cheap jordan shoes on July 08, 2009 at 02:00 AM IST #

Pretty good post. I just found your site and wanted to say that I have really enjoyed browsing your posts. In any case I’ll be subscribing to your blog and I hope you post again soon!

Posted by air jordan on September 17, 2009 at 06:08 AM IST #

Aion kinaAION2009 year in September the latest high-speed Download,AION2009 year in September the latest careers information

Posted by Aion kina on September 22, 2009 at 11:59 AM IST #

metin2 yang AION2009 year in September the latest high-speed Download,AION2009 year in September the latest careers information

Posted by metin2 yang on September 22, 2009 at 12:01 PM IST #

dofus kamas AION2009 year in September the latest high-speed Download,AION2009 year in September the latest careers information

Posted by dofus kamas on September 22, 2009 at 12:03 PM IST #

It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.

Posted by Christian louboutin shoes on October 27, 2009 at 06:50 AM IST #

Bing is a really overlord!! support Bing~~

Posted by street lights on October 27, 2009 at 11:42 PM IST #

very nice post.
i like it very much.
thanks.

Posted by dofus kama on November 05, 2009 at 05:56 AM IST #

yeah ,i think so

Posted by christian louboutin on November 15, 2009 at 04:36 AM IST #

i like post,thank you

Posted by brand-clothing on December 01, 2009 at 05:25 AM IST #

As the blindingly red box above says…. Goodbye cruel server. I am off to SquareSpace where I hope to breathe fresh life into writing about aspects of life that interest me, but probably no-one else.

Posted by ed hardy clothing on December 02, 2009 at 03:06 AM IST #

This is some very valueable information, thank you very much.

Posted by us drugstore on December 03, 2009 at 03:52 AM IST #

Do you need <a href="http://www.rappelzrupees.net/">Rappelz Rupees</a> in the game? Do you have enough <a href="http://www.rappelzrupees.net/">Rappelz gold</a>? Now we can offer you the cheapest <a href="http://www.rappelzrupees.net/">Rupees</a> in the market. Come and have a look.

Posted by Rappelz Rupees on December 05, 2009 at 04:52 AM IST #

Do you need [url=http://www.rappelzrupees.net]Rappelz Rupees[/url] in the game? Do you have enough [url=http://www.rappelzrupees.net]Rappelz gold[/url]? Now we can offer you the cheapest [url=http://www.rappelzrupees.net]Rupees[/url] in the market. Come and have a look.

Posted by rappelzrupees on December 05, 2009 at 04:53 AM IST #

Great Overview on Crossbow Ben! And thanks everyone for
trying it out. You can find more details relating to architecture
or building advanced virtual networks aka Virtual Wire at
Christian Louboutin Shoes will be the nice presents

Posted by Christian Louboutin on December 25, 2009 at 01:03 AM IST #

In here all <a href="http://www.buymabinogigold.com/">Mabinogi Gold</a> is cheap, if you now play the game, you can come here to <a href="http://www.buymabinogigold.com/">Buy Mabinogi Gold</a>, in here you can find that the <a href="http://www.buymabinogigold.com/">Cheap Mabinogi Gold</a> is cheapest in the market.

Posted by Cheap Mabinogi Gold on January 03, 2010 at 04:22 AM IST #

<p>Your article is so good that I can’t miss.And I’m prode of you as the same as the <a href="http://www.christianlouboutinshoesdirect.com/" target="_blank">christian louboutin</a>.If you heard it,you will know that it is a high quality + a famous brand + good service ,so you can’t miss it also.

Posted by christian louboutin on January 07, 2010 at 08:57 AM IST #

hello, welcome to our game gold website

Posted by aion kinah on January 09, 2010 at 02:50 AM IST #

chanel jewelry

Posted by chanel jewelry on January 13, 2010 at 10:06 AM IST #

the article is in reality the sweetest on this valuable topic. I fit in with your conclusions and will thirstily look forward to your approaching updates. A simple thanks will not just be complete for the exceptional lucidity in your writing.

Posted by uggs on January 26, 2010 at 04:17 AM IST #

520 6630
welcom to our online fashion store...

Posted by ルイヴィトン バッグ on January 30, 2010 at 01:21 AM IST #

[URL=http://www.christianlouboutinshoes.me]Christian Louboutin Shoes[/URL]
[URL=http://www.christianlouboutinshoesstore.com]Christian Louboutin Shoes[/URL]
[URL=http://www.christianlouboutinshoesmart.com]Christian Louboutin Shoes[/URL]

Posted by may on February 01, 2010 at 05:56 AM IST #

nice

Posted by chi flat iron on February 26, 2010 at 01:26 AM IST #

Do you know<a href="http://www.buynostalegold.com/">nostale gold</a>?if you play the online game,you will know<a href="http://www.buynostalegold.com/">nostale online gold</a>is the game gold.in the game,if you had more<a href="http://www.buynostalegold.com/">buy nostale gold</a>,you will had a tall level. But if you want to<a href="http://www.buynostalegold.com/">cheap nostale gold</a>, you can come here and spend a little to bought<a href="http://www.buynostalegold.com/">nostale money</a>?

Posted by nostale gold on February 26, 2010 at 04:21 AM IST #

Do you know<a href="http://www.lataleely.com/">La Tale Ely</a>?if you play the online game,you will know<a href="http://www.lataleely.com/">La Tale online Ely</a>is the game gold. In the game,if you had more<a href="http://www.lataleely.com/">LaTale Ely</a>,you will had a tall level. But if you want<a href="http://www.lataleely.com/">La Tale gold</a>,you can come here and spend a little money to bought<a href="http://www.lataleely.com/">La Tale online gold</a>.Quickly come here.

Posted by La Tale Ely on March 04, 2010 at 12:38 AM IST #

Thank you for sharing out

Posted by jordan shoes on March 08, 2010 at 11:23 PM IST #

Do you know 2moons guild if you play the online game, you will know that 2moons guild is the game gold, in the game if you had more 2moons quest you will had a tall level, but if you want to 2moons cheats you can come here and only spend a little money then can bought the 2moons forums Quickly come here.

Posted by 2moons quest on March 10, 2010 at 02:22 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

I am Vikram Aroskar working in the Java team based out of India.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today