What is your preferred scripting language in java world (scripting language on JVM) and way? When do you prefer your scripting language over java (in what situations for example for prototyping)? Do you use it for large projects or for personal projects only?
8 Answers
For me, Clojure wins hands down. Being a Lisp, it's concise and dynamically typed, it has enormous expressive power so I can write a lot of functionality in a few lines. And its integration with Java is unsurpassed – I'm only partly joking when I say Clojure is more compatible to Java than Java itself. As a result, the entire breadth of Java libraries, both from the JDK and 3rd party, is fully useable.
Finally, with a little care Clojure code can be as fast as Java code, so I'm not even losing performance.

- 66,391
- 18
- 125
- 167
-
2+1 - as Stuart Halloway has pointed out: Clojure is a better Java than Java. – wlangstroth May 26 '10 at 17:37
My favorite is Jython, and I use it by embedding a Jython interpreter in my Java application. It is being used in commercial projects, and it allows to easily customize the application according to the customers' needs without having to compile anything. Just send them the script, and that's it. Some customers might even customize their application themselves.

- 36,252
- 29
- 106
- 169
I've successfully used Groovy in a commercial project. I prefer scripting languages because of duck typing and closures:
def results = []
def min = 5
db.select(sql) { row ->
if (row.value > min)
results << row;
}
Translation: Run a SQL query against the database and add all rows where the column "value" is larger than "min" to "result". Note how easily you can pass data to the inner "loop" or get results out of it. And yes, I'm aware that I could achieve the same with SQL:
def results = []
def min = 5
db.select(sql, min) { row ->
results << row;
}
(just imagine that the String in "sql" has a "?" at the right place).
IMHO, using a DB with a language which doesn't offer rich list operations (sort, filter, transform) and closures just serves as an example how you should not do it.
I'd love to use Jython more but the work on Jython 2.5 has started only recently and Python 2.2 is just too old for my purposes.

- 321,842
- 108
- 597
- 820
-
Not only could you achieve the same with SQL, it would be more efficient and easier to read if you did... – Steven Huwig Mar 18 '09 at 09:45
-
1... and I wouldn't have a simple example that would fit into five lines and which everyone here could understand without 10 lines of explanation. Mind the intent, Sir. – Aaron Digulla Mar 18 '09 at 10:01
I might prefer Scala, but I can't say, still learning. At the moment using Groovy to write small utility programs. Haven't tried even Groovy on Grails. Heard lots of good about Lift Framework for Scala as well.

- 39,541
- 12
- 93
- 133
-
I was a Scala fanboy for a while (not intended as an insult, it's directed at myself, not you) but I found myself annoyed by its pedantry concerning types and its somewhat complex syntax. It feels like a language with too many kitchen sinks bolted on. I found Clojure to be more comfortable. Of course, everybody's mileage may vary. – Carl Smotricz Dec 11 '09 at 22:00
JavaScript Rhino has a compelling advantage -- it is included with the JDK. That being said, later versions of Rhino than the one with Java 6 have nice features like generators, array comprehensions, and destructuring assignment.
I favor using it whenever the ceremony of handling Java exceptions clutters up the code for no real benefit. I also use it when I want to write a simple command-line script that takes advantage of Java libraries.

- 20,015
- 9
- 55
- 79
Java. Seriously. It's a powerful, easy-to-use (if a tad verbose) language that everybody knows. The integration with Java is great.

- 145,806
- 30
- 211
- 305
How about SISC (Second Intepreter of Scheme Code)?

- 1,910
- 20
- 44
-
+1 for pointing this language out. Looks very cool, especially if you're a seasoned Scheme specialist unwilling to switch to Clojure. – Carl Smotricz Dec 11 '09 at 22:03
The company I work for embeds Groovy into a Java/Spring website, which is deployed on a number of sites. The scripts are stored externally of the compiled WAR file, and allow us to manipulate some of the site logic without having to roll out new WAR's to each site. So far, this approach has worked very elegantly for us.
A particularly nice feature of Groovy is that it can closely resemble Java code, which makes it very easy to port existing Java classes to it.

- 17,426
- 15
- 71
- 93