aspose file tools*
The moose likes Features new in Java 7 and the fly likes Dynamic Language Support in Java 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Dynamic Language Support in Java 7" Watch "Dynamic Language Support in Java 7" New topic
Author

Dynamic Language Support in Java 7

karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

Hi,
I have read the Article on Java 7 & the features it provides. I learned that it supports Dynamic Language . Any comments or discussions on this topic would eventually be more helpful for me as well as for others. Thanks in Advance.


"Learning is a Culture where your Eagerness & Curiosity plays a major Role".
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Java has long supported dynamic languages through external libraries like Apache BSF and (since Java 6) the javax.scripting package. Searching for those will find articles and examples code.

What is new in Java 7 is JVM support for a common feature needed by dynamic languages - this should improve performance quite a bit.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I read the other day that invokedynamic will actually be in 6u23, although I don't know if it's actually true or not. If so, I can't wait for all my favorite real languages to take advantage of it.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

David Newton wrote:If so, I can't wait for all my favorite real languages to take advantage of it.


For many years I have been trying to find a real world example of where scripting in Java was needed and not used just for the sake of being used. Do you have an example?



Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
James Sabre wrote:For many years I have been trying to find a real world example of where scripting in Java was needed and not used just for the sake of being used. Do you have an example?

"Needed" is a strong word; there are always other possible ways. Just like no high-level programming language is "needed" because one can always resort to assembler. It's more a question of making functionality available to power users. For example, the image processing app ImageJ uses JavaScript as a means for users to write scripts that automate image processing tasks: http://pacific.mpi-cbg.de/wiki/index.php/Javascript_Scripting
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I think that it won't be much of an impact for the java language but mostly for the java platform. It allows many dynamic languages to run on the JVM without the former performance loss (maybe even a performance gain with all of the JVM optimalizations). But with all the benefits of the platform (OS independent, Garbage Collection...).


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

James Sabre wrote:For many years I have been trying to find a real world example of where scripting in Java was needed and not used just for the sake of being used.

That statement amazes me. I could just as easily say "I've been trying to find a real-world example of where a higher-level language than assembly was needed and not used just for the sake of being used," no?
Do you have an example?

Any DSL: have you used anything like Rake, Rant, Gradle, Gant? Ever needed one yourself? Ever been frustrated with the limited models of abstraction Java provides? Ever wanted to not write high-ceremony boilerplate code continuously? Ever get tired of repeating yourself?

I don't really know how to process that question--what else have you programmed in other than Java? The answer to that will direct my answer(s).
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

David Newton wrote:
James Sabre wrote:For many years I have been trying to find a real world example of where scripting in Java was needed and not used just for the sake of being used.

That statement amazes me. I could just as easily say "I've been trying to find a real-world example of where a higher-level language than assembly was needed and not used just for the sake of being used," no?

I don't understand your amazement! Once one has made the decision to use Java then what rational makes writing some of the code in Javascript (or Ruby or Python or ...) rather than using Java. I have seen many supposed uses of scripting in Java but none so far that convinces me that the scripting approach is the way to go. I can't comment on the use of Rake, Rant, Gradle, Gant since I don't have a clue what they do but you have convinced me to look at them for applicability.

Do you have an example?

Any DSL: have you used anything like Rake, Rant, Gradle, Gant? Ever needed one yourself? Ever been frustrated with the limited models of abstraction Java provides? Ever wanted to not write high-ceremony boilerplate code continuously? Ever get tired of repeating yourself?

I need to understand what you mean by " Ever wanted to not write high-ceremony boilerplate code continuously? ". Writing boilerplate code to be compiled and integrated into an application is standard. I tend to use XSLT for this and this also handles the "Ever get tired of repeating yourself?". Obviously you mean more than this but what more and why?

I don't really know how to process that question--what else have you programmed in other than Java? The answer to that will direct my answer(s).

In roughly chronological order - H Code (1964), FORTRAN 2, FORTRAN 4, CSMP, IBM360/370 assembler, PDP8 assembler, C, APL, PASCAL, 6502 Assembler, FORTRAN 90, 8086/88 assembler, 68000 assembler, ADA, bash, sh, C++, SQL, Perl, Java, XSLT, Javascript, Python plus a couple of DSP chips.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

James Sabre wrote:Once one has made the decision to use Java then what rational makes writing some of the code in Javascript (or Ruby or Python or ...) rather than using Java.

Because there are things Java is not good at expressing or doing. IMO, a *lot* of things, but I come from a language background where such things are trivial.
Writing boilerplate code to be compiled and integrated into an application is standard.

Sure it's standard--*in Java*.
I tend to use XSLT for this

You write code generators in XSLT?!
In roughly chronological order - H Code (1964), FORTRAN 2, FORTRAN 4, CSMP, IBM360/370 assembler, PDP8 assembler, C, APL, PASCAL, 6502 Assembler, FORTRAN 90, 8086/88 assembler, 68000 assembler, ADA, bash, sh, C++, SQL, Perl, Java, XSLT, Javascript, Python plus a couple of DSP chips.

That explains some of your confusion--although with Python and JavaScript in there I'd have assumed more familiarity with the concepts of meta-programming, first-class methods, cleaner closures, and so on. Things Java is bad at, and higher-level languages take for granted.

Our backgrounds are similar (minus H Code, CSMP, and 360/370 stuff), but I also spent a *lot* of time in Lisp, Smalltalk, Ruby, and now Groovy, JavaScript, and Clojure: these are languages that allow a much greater freedom of expression, reduction of boilerplate via stronger support for abstractions. The problem spaces I tend to be in also demand a high level of customizability, which Java is bad at: Java + scripting alleviates some of this pain (eliminating Java eliminates it altogether), and eliminates it more easily than things like compilation-on-the-fly or dynamic bytecode generation (which obviously work, but meh).

I'm amazed because I have to struggle to think of applications that *can't* benefit from the use of scripting or the use of non-Java JVM languages--but your background suggests a relatively static outlook on things. Although the Python and JavaScript confuses me, since I'd think that would lead to a similar outlook, but how a language is used makes a difference, and it's possible you just approach them differently than I do.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

David Newton wrote:
James Sabre wrote:Once one has made the decision to use Java then what rational makes writing some of the code in Javascript (or Ruby or Python or ...) rather than using Java.

Because there are things Java is not good at expressing or doing. IMO, a *lot* of things, but I come from a language background where such things are trivial.

I have never said that Java should be used in place of scripting languages. Far from it. I am trying to find a real world Java application where including a part in Javascript or Python makes economic sense. I'm not saying there is not a case for this - just that I have yet to see one.

Recently I have been testing a load of Javascript cryptography code using Java but that is for testing only. I would never use Javascrypt cryptography in Java.

Writing boilerplate code to be compiled and integrated into an application is standard.

Sure it's standard--*in Java*.
I tend to use XSLT for this

You write code generators in XSLT?!

Yes! Not ideal and when that fails I use Java or Perl. I could use almost any high level language (though I would probably not use FORTRAN) but that would be run outside of Java. It would not be run as a script in Java unless maybe I was creating an Ant task that executes the script.

In roughly chronological order - H Code (1964), FORTRAN 2, FORTRAN 4, CSMP, IBM360/370 assembler, PDP8 assembler, C, APL, PASCAL, 6502 Assembler, FORTRAN 90, 8086/88 assembler, 68000 assembler, ADA, bash, sh, C++, SQL, Perl, Java, XSLT, Javascript, Python plus a couple of DSP chips.

That explains some of your confusion--although with Python and JavaScript in there I'd have assumed more familiarity with the concepts of meta-programming, first-class methods, cleaner closures, and so on. Things Java is bad at, and higher-level languages take for granted.

Once again - I don't think I have any confusion and I'm not trying to find a use for scripting languages. Just a real world use of scripting within Java. Of course I am aware of the concepts of meta-programming, first-class methods, cleaner closures but why when one is coding in Java does one need to go into Javascript or Python to make use of these.

Our backgrounds are similar (minus H Code, CSMP, and 360/370 stuff), but I also spent a *lot* of time in Lisp, Smalltalk, Ruby, and now Groovy, JavaScript, and Clojure: these are languages that allow a much greater freedom of expression, reduction of boilerplate via stronger support for abstractions. The problem spaces I tend to be in also demand a high level of customizability, which Java is bad at: Java + scripting alleviates some of this pain (eliminating Java eliminates it altogether), and eliminates it more easily than things like compilation-on-the-fly or dynamic bytecode generation (which obviously work, but meh).

OK - again, I am not arguing against scripting but am asking for a real world application that uses Java + scripting with more than just a token bit of scripting.

I'm amazed because I have to struggle to think of applications that *can't* benefit from the use of scripting or the use of non-Java JVM languages

But can you give me an example that does actually use scripting to advantage?
--but your background suggests a relatively static outlook on things. Although the Python and JavaScript confuses me, since I'd think that would lead to a similar outlook, but how a language is used makes a difference, and it's possible you just approach them differently than I do.


Yes, I do have rather a static outlook. I'm also a bit of a sceptic when it comes to fads and nothing has yet convinced me that Java + scripting is more than a fad. Only a real world example will convince me. I am open to being convinced but not just by argument because I have seen a lot of argument but never a single concrete real world example.

P.S. As far as I can tell from a quick burst of Google, Rake, Rant, Gradle and Gant are just build systems and unless there is something to them I am missing I don't see where Java + scripting comes in.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

They're DSLs. DSLs are the big win for Java + scripting. (Well, and dynamic functionality, which is the example I gave but you ignored.) Under what circumstances the DSL is run is immaterial.

So, yet another example: rules engines. I'm building a rules engine to aid in client configuration. The rule relationships in the one I'm building are simple, so it basically a trivial Groovy internal DSL rather than something like Jess, which is also Java + scripting. The equivalent Java code would be maybe 2-3x as long, and would be completely opaque to any stakeholder other than development. But development doesn't want to be involved in finding and diagnosing client configuration issues. So the DSL is used to enforce configuration requirements, product rule documentation, and drive the configuration process.

It's like Lisp macros: you won't see it until you see it, then it cannot be unseen. It may just be that the problem spaces you're in have no use for anything even remotely dynamic; I just happen to have not been in those spaces for 25 years (and don't really know what space that would be, 'cuz I've been in a *lot* of spaces).

(It's JavaScript, btw, not Javascript. And why not use a simple templating engine for code generation? Why use XSLT?!)
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

David Newton wrote:They're DSLs. DSLs are the big win for Java + scripting. (Well, and dynamic functionality, which is the example I gave but you ignored.) Under what circumstances the DSL is run is immaterial.


I didn't think I had ignored anything significant - obviously I did. I shall take a more detailed look at DSLs since I obviously don't understand their relationship with Java + scripting.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
James Sabre wrote:I'm not saying there is not a case for this - just that I have yet to see one.

I'm not trying to find a use for scripting languages. Just a real world use of scripting within Java.

I am not arguing against scripting but am asking for a real world application that uses Java + scripting with more than just a token bit of scripting.

But can you give me an example that does actually use scripting to advantage?

Only a real world example will convince me. I am open to being convinced but not just by argument because I have seen a lot of argument but never a single concrete real world example.

But the example I posted doesn't convince you? Extending desktop apps through user-provided scripts is probably one of the major areas in which javax.scripting/BSF is applied (although the same would also work for extending web apps, provided proper security precautions are taken).
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Text editors, too. Spreadsheets.

I mean, there are an unlimited number of usecases for Java + scripting. I see it everywhere, so it's difficult for me to unsee it.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Lester Burnham wrote:
James Sabre wrote:I'm not saying there is not a case for this - just that I have yet to see one.



Sorry I took so long to get round to your post. I was too engrossed in my dialogue with David Newton . ImageJ does seem to be a real world example where Java + scripting makes sense. Thanks for that.

James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

David Newton wrote:Text editors, too. Spreadsheets.

I mean, there are an unlimited number of usecases for Java + scripting. I see it everywhere, so it's difficult for me to unsee it.


There does seem to be a very strong case for writing DSLs where the DSL is itself a scripting language interfaced to Java. I have done something similar for processing oil field data but I used JFlex and CUP. If the scripting API had been available at that time (JDK1.4 ish) and if I had thought about it then may maybe I would have implemented it via the scripting API.

Your DSLs do seem to a legitimate use of the scripting API and when taken with Lester's IMage example I have to admit that these are real world uses of Java + scripting.

Time to take my blinkers off.
karthik Suryanarayanan
Ranch Hand

Joined: Oct 07, 2009
Posts: 110

James, David & Lester , though i do not have that much knowledge on Scripting , i'm very happy to learn quite a few things from you guys. All your experiences just amazes me. I'm very happy to learn such things from you guys. And also could you help me out with some reference sites for Learning about DSL's. Thanks in Advance.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

David Newton wrote:I read the other day that invokedynamic will actually be in 6u23, although I don't know if it's actually true or not. If so, I can't wait for all my favorite real languages to take advantage of it.


Do you still have that link?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I'll add another use is having a Groovy console running in your admin page of your web app which you can use to dynamically interrogate your running Java app. Powerful stuff.
 
 
subject: Dynamic Language Support in Java 7