First of all my understanding about scripting language after reading some stuff on web, is we can classify as scripting language which we user can run straightaway without need of compiling. Recently i worked on opensource product xwiki where I saw they are using groovy as scripting language i.e from user interface I can write small program and once I save it, it gets compiled and executed at back end. How they are doing it is simply passing the program as string and then compile and run it with groovy compiler. If this way groovy can be treated as compiling language because for user experience is he does not have to compile the code and run on the fly (though internally it also get compiled in to byte code).
If that is true we can also achieve the similar stuff with java too i.e
Process process1 = Runtime.getRuntime().exec("javac "+stringContainingProgram);
and the get the compile code from input stream than run it .
Can i say in this aspect we can treat java as scripting language?
What you have in your example is not Java. It is an expression language with a Java-like syntax. In real Java, a declaration has to be embedded in a class or method.
So based on that example, you can’t say that Java is a scripting language. You could create a Java-like scripting language, but you need to address some usability issues. Like a different syntax for imports … if you want your scripting language to be interactive.
Then there is the issue that a scripting language that requires the user to explicitly declare variables and their types is not what people want. Real Java is fundamentally a statically typed language with explicitly typed declarations. Scripting languages are (generally speaking) dynamically typed.
Not really. A “scripting language” is a language that is commonly used for scripting. That is just about all you can say. We can’t even clearly define what “scripting” is.
There’s no fundamental law of nature that says you cannot do scripting with a statically typed language. It’s just … well … not what people want.
That is correct. It doesn’t fundamentally affect the usability of a language for scripting purposes.
Now, you might argue that if the user has to explicitly compile the scripts before running them, then that is not scripting. Perhaps that is something that separates “ordinary” programming from “scripting”. However, the risk in this is that we are implicitly constraining “scripting language” and “scripting” to fit/suit our particular biases.
If you read through this and the other answers, we are all basically agreeing on one point. There is no useful definition of what a scripting language is, and therefore it is not possible to say if Java is one.
A more answerable question is whether Java would be a good language for scripting … and my answer would be that I don’t think so.