I know I will get downvotes for my answer, but ..Dave Newton is absolutely right. The term is too nebulous...
In your example, the groovy code doesn't have to be compiled. IMHO, a more typical use of groovy in such a case would be to use the groovy interpreter.
And yes: java can be used as scripting language. I've seen enterprise products where you can write litte scripts in java code. The program wraps it in a class, compiles and executes it.
So if you compare the approches, it doesn't matter for the user if a “real scriptin“ language like groovy is used or java is turned through little tricks into one.
Btw: most java statement run in groovy too... So if you just take a look at a code fragment like
res = 5 * 16 + 2
You can't tell if this is a script or part of something not scripted. You even can't tell which language it is written in!
So, coming back to your original question:
I wouldn't say that you can treat java as a scripting language, but you can fulfill your scripting needs with java in may cases, but people will miss the shortcuts which come with “real“ scripting languages like dynamic languages.
Update:
as you said "java can be used as scripting language. I've seen
enterprise products where you can write litte scripts in java code" It
would be helpful if you can brief what kind of little scripts you are
talking aout here?
I am talking about little scripts which extend products beyond the normal functionality: Visual Basic in MS Office products, Groovy in Bonita (a workflow product) and Groovy, JavaScript and Java (yes! Java!) in Jasper iReports (a report generator)
BTW: you'll find a good comparision between the use of Java and Groovy in Jasper here: http://jasperforge.org/uploads/publish/ireportwebsite/IR%20Website/iReport_groovy.html
It show you that Java can be used as scripting language, but other solutions are better :-)
I am asking this becoz most of the web says that A scripting language
is usually a language which allows automation (scripting) of tasks. If
i go by this definition then every language becomes scripting language
becoz we can automate one or other type of task with any language.
For me, a scripting language is not only one which allows the automation of tasks. For me, PHP, Javascript, Visual Basic and Groovy are also scripting languages. And ehat about Post*Script*?
btw: just found http://www.beanshell.org/ - a fully Java compatible scripting language.
As I already mentiones, IMHO, many languages can be used as scripting language, but some are better suited :-)