The moose likes Beginning Java and the fly likes Scripting in java 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Scripting in java 6" Watch "Scripting in java 6" New topic

Scripting in java 6

Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
Hi Everybody

I read scripting in java and run few example successfully. But I am unable to understand why we use scripting in java. GWT produce java script from java code is understandable.

But on Server side we use javascript code is something not usual.

If any body tell me when and when we really need this feature. A good example is really helpful to clear the concept.

Thanks in Advance

Thank You & Best Regards,

Syed Saifuddin,
Senior Software Engineer

SAP Oracle AIX & Java Training
Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
Hi Everybody

its challenge for everyone. Is there no guru for java 6.

Help me and help the community
Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
Hi EveryOne

What I find in the scripting functionality in java6 is just for command line testing of java script.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

I don't know how useful it is to be able to run JavaScript on the server. Some people think that developing with a scripting language is easier and faster than in a more strict language such as Java, but I don't agree with that - and quickly hacking an entire application together in a scripting language leads to code that is difficult to maintain. Also, the performance of scripting languages is almost always a lot less than a compiled language.

However, some scripting languages like PHP or Ruby are popular for web applications and the JDK 6 scripting API makes it easier to run such scripts from your Java program on the server.

But there are other uses you can think of for the scripting API. If you look at applications such as Word and Excel, you can script those using Visual Basic, to automate repetitive tasks that are tedious to do by hand. You can script Photoshop with JavaScript or AppleScript, which can be very useful if you for example want to perform certain operations on a large number of images. I can imagine that it would be useful to script a Java desktop application like that.
[ August 20, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
You wouldn't code an entire web app or desktop app in a scripting language. You might use them if doing so provides an advantage over using Java. No language is perfect for everything, and Java is no exception.

Jesper�s example of AppleScript is perfect for this. In case you�re not familiar with it, it�s the system scripting language on Mac OS X, in some aspects similar to Windows Scripting Host on Windows. It can do many things that would be decidedly difficult to do in Java, maybe impossible to do without resorting to native code and JNI. Having a formal API to access it makes it easier and more stable to work with than executing commands using Runtime.exec or ProcessBuilder.

(Disclaimer: The next paragraph is about a project I implemented, but I think what I write as pretty objective). Another example is an API for Prolog. Prolog is not really a scripting language, but a regular programming language which is very useful for certain classes of problems (but would be hard to use for some others that in turn are simple in Java). By adapting it to the BSF API -which is kind of similar to the javax.scripting API, but runs on older JVMs as well- it became possible to drive Prolog programs from within Java code, and thus use the best of both worlds wherever appropriate. (By "both worlds" I mean that Prolog is logic-oriented, not object-oriented like Java, or procedural like C, and programming in it is rather different from either of those.)

So, in short, none of the languages usable through BSF or javax.scripting replaces Java - they augment it.
I agree. Here's the link:
subject: Scripting in java 6
It's not a secret anymore!