1

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?

1
  • 4
    Guys really feel bad when people downvote for any question without stating reason. Its perfectly fine to downvote the question but at least person should also state the reason for that so that next time person can keep that fact in mind. Commented Jun 3, 2012 at 4:59

4 Answers 4

3

I think you are confusing the terms 'scripting language' and 'interpreted languages'.

An interpreted language is one that isn't pre-compiled before runtime.

A scripting language is usually a language which allows automation (scripting) of tasks.

Java is a little more confusing as it does have a compiling phase where the java code is translated into JVM byte code, this byte code is then interpreted at run time, thus Java has features of both compiled and interpreted languages.

Using the Runtime.GetRuntime().exec() you are able to call commands at run time, however this is the same as having a bash script which does the same (or typing them into a terminal for that matter).

In this case you outlined you are using java to call the compiler explicitly and the next logical step would be to run it, however the code is not running from within your Java code, your Java code is merely calling it.

Short answer is no, Java isn't a fully interpreted language.

Sign up to request clarification or add additional context in comments.

4 Comments

Another way to look at it: Compiled languages can give you compilation errors and runtime errors. Interŕeted languages don't give compilation errors. You will never see a javascript compilation error, for example.
That really depends on the interpreting technology you are using, with a JIT compiler/interpreter you are correct, however traditionally interpreted languages have been 'entirely' compiled before being run and with this it could be possible to detect many errors. Due to the nature of dynamic typing this gets quite messy though.
But the code could be running from within your Java code, it just isn't in that example.
Well you can write an interpreter in any language. You can have in memory classes that then get compiled and run within 'run time'. From memory the JVM also includes a javascript engine. There is also the option of using a Java library which includes a Java interpreter. If I really want I can use a C interpreter and thus use C as an interpreted language.
2

IMO the term "scripting language" is too nebulous to be debated in a meaningful way. Is Groovy a scripting language? It can be compiled ahead of time, or just in time.

Is a purely-interpreted language a scripting language? IMO how the language is executed isn't important, because I wouldn't call early interpreted BASICs "scripting languages".

Is a statically-typed language a scripting language? Treading on something interesting here... but what about languages with optional typing?

For me it comes down to "do I have to manually compile the code". Can Java be a scripting language? Tricky... is an editor plugin that conforms to an interface a "user script", or has it become simply "part of the editor codebase"? I don't have an answer I could defend with any certainty, and could see arguing either side.

If cornered, honey badger doesn't give a sh*t, and says Java isn't a scripting language, and Groovy can be. But huge systems are written in "scripting" languages, like, say, Perl. (Whether they should be is... debatable.) Now it's down to "what differentiates a scripting language from a programming language?"

Nothing, really. IMO the differentiation is almost always meaningless.

Comments

1

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.


Can i say java is not scripting language as it is not dynamically typed language?

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.

Regarding compilation whether its just in time or ahead of time, It is not a criteria to qualify any language for scripting language. Right?

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.

3 Comments

so can i say scripting language is dynamically typed language but java is statically typed. So its not classify for scripting language.Regarding compilation whether its just in time or ahead of time, does not qualify any language for scripting language
I don't understand what you are saying. I cannot even tell if you are asking me a question or making a statement.
Hope this comment makes sense. Can i say java is not scripting language as It is not dynamically typed language? Regarding compilation whether its just in time or ahead of time, It is not a criteria to qualify any language for scripting language. Right?
1

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 :-)

2 Comments

Hi Ralf 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 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 example if want to caculate 5*1 to 5*20 i acn do it any language be it c , c++,java
etc. That why scripting language terms confuses me a lot?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.