Discussions

News: Java 6 scripting article from OCIWeb

  1. Java 6 scripting article from OCIWeb (17 messages)

    Paul Jensen has written an article called "Scripting Support in Mustang," covering some of the APIs used to interact with scripting languages in the next revision of Java SE, including invocation of scriptlets (meaning 'fragments of scripting code'), storage of variables for scriptlets, and use of function invocations.
    While not part of J2SE, the JSR 223 specification describes an optional Web Scripting Framework which includes an HttpScriptContext integrated with an HttpScriptServlet located a proposed javax.script.http package. In fact, PHP and JavaScript integration for web page generation was an initial impetus for the JSR. This scope was expanded over time to be the much more general solution described above. We can anticipate that future versions of J2EE will introduce the originally envisioned Web Scripting Framework.

    So what is gained through JSR 223 and how can it be put to use? Certainly scripting is a convenient and efficient means to learn and prototype. In the context of production Java applications, it can also be useful to provide scriptable extension points for sophisticated users. It can also be useful for altering the state of running applications for debugging and monitoring where alternatives such as JMX are not available or sufficient. Naturally, security concerns will dictate reasonable usage for these scenarios.

    However, the above only scratches the surface of the capabilities of scripting languages. In general, they offer greater flexibility and power than statically-typed languages like Java. Scripting languages continue to gain in popularity and capability, providing significant productivity gains over Java only solutions (witness Ruby on Rails). JSR 223 defines an integration standard, establishing a foundation for leveraging the strengths of both approaches.
    The invocation of external scripting language code seems to be pretty simple, simple enough that easy examples should be enough to show the capabilities and limitations of the API. However, the article points out that the JavaScript and Pnuts are the only languages available so far, with little focus on how to bind in other scripting languages, which would be of more interest (and use), as it would provide the capabilities of native Perl and Ruby runtimes to Java.
  2. Java 6 scripting article from OCIWeb[ Go to top ]

    I guess it is good that they are standardizing this stuff but when I heard about scripting updates to JDK 6 I was hoping that some hooks were being put into the JVM itself for JVM-compatible scripting languages (Groovy, JPython, JRuby).

    I'm not even a novice on this topic (sub-novice?) but I've read a bit on how it is somewhat awkward to write a scripting language on top of the JVM. Probably why Groovy is taking so long to get production-ready.

    Is there more to scripting and JDK 6 or is this it?
  3. Groovy *does* support JSR-223[ Go to top ]

    However, the article points out that the JavaScript and Pnuts are the only languages available so far, with little focus on how to bind in other scripting languages, which would be of more interest (and use), as it would provide the capabilities of native Perl and Ruby runtimes to Java.

    The article is wrong.

    JavaScript and Pnuts aren't the sole languages that can be used through JSR-223. Groovy doesn't provide a support for this JSR itself, since the Reference Implementation you can download already provides the hooks to use Groovy as an embedded language of the scripting engine.

    Unfortunately, it uses a very old build of Groovy, so the best would be to upgrade to a more recent one, and simply change the jar yourself.
  4. Java 6 scripting article from OCIWeb[ Go to top ]

    I was pretty disappointed with this API, now we have the EL API in JEE and the Scripting API not in SE 6. IMHO, the EL API does a lot more for flexible property and variable resolution, but from a spec standpoint, is tied to the EL (or JSTL) markup. From an API standpoint, you could use whatever scripting language you wanted.

    I agree that for JSE to really support dynamic languages, it will have to give them first-class accomodations at the byte code level. JSR 223 is yet another facade API we could probably do without.
  5. el/groovy[ Go to top ]

    Yes, if EL would move from EE to SE that be good, but there is more to scripting. Key sentence in article is:

    "J2SE 1.6 includes a modified version of the Rhino JavaScript"
    and I do not think that is a great idea.

    Of course I am a huge fan of Groovy.

    .V
    ot: Fedora 5 (Linux for those that do not understand tech) now ships w/ Ruby included
    (and EJB servers built in w/ no Sun Java, and C# GUI apps, ex:
    http://fedoraproject.org/wiki/Tours/FedoraCore5/009_F-Spot )
  6. el/groovy[ Go to top ]

    Jakarta has an open source EL library. I'm using it and it works very well.

    http://jakarta.apache.org/commons/el/
  7. ...is a multi-line string syntax.

    How un-fun is it to have to concatenate strings together to create a script more useful than print('hello').. or whatever. And how unreadable is it to put it all on one line?

    This goes for any kind of scripting language (e.g. JavaScript), as well as any other language supported by an API via strings, not the least of which is SQL!

    I'd love to see something like:

    String sql = ${
      SELECT FIRST_NAME as "FirstName", LAST_NAME as "LastName"
      FROM CUSTOMERS
      WHERE CUSTOMER_ID = ?
    };

    Wouldn't that be cool? At least cooler than this:

    String sql = "SELECT FIRST_NAME as \"FirstName\", LAST_NAME as \"LastName\"" +
                 "FROM CUSTOMERS" +
                 "WHERE CUSTOMER_ID = ?";

    (For fun, can you spot the error in the SQL string above?)

    Multiline string syntax would rock.

    Cheers,
    Clinton
  8. for fun[ Go to top ]

    There is no space after "CUSTOMERS" ?
    (2nd sql string)
  9. for fun[ Go to top ]

    There is no space after "CUSTOMERS" ?(2nd sql string)

    Yep. And also after the first line (or before the second) etc. What a mess, eh?

    Cheers,
    Clinton
  10. Python has multiline strings, and so does groovy...
  11. I applaud Sun for making the JVM more amenable to scripting languages. A terse, dynamic language that can take advantage of all of Java's facilities is a great fit for many uses, not just quick-and-dirty prototypes.
    However I believe that most developers would get a greater productivity boost if Sun finally fixed HotSwap and allowed more runtime changes to classes.
    Isn't shortening the code-compile-run loop a prime motivator for many Groovy/Python/Jython/Ruby/JRuby users?
    The time and effort saved by typing less characters with a scripting language to implement an operation is peanuts compared to the time it takes to redeploy and restart an application after adding a method to a class.
    I have a hard time understanding why VisualAge five years ago was able to deliver runtime changes to classes, but today Java does not and it is not slated to appear in the next release.
    If Java focused on making actual Java programmers more productive, there would be a lot less talk about scripting languages.
  12. I have a hard time understanding why VisualAge five years ago was able to deliver runtime changes to classes, but today Java does not and it is not slated to appear in the next release.If Java focused on making actual Java programmers more productive, there would be a lot less talk about scripting languages.

    I have no idea of what you're talking about. Rational Application developer does that, just save the class and run.

    And I believe it must be a standard feature of any serious IDE.
  13. I have no idea of what you're talking about. Rational Application developer does that, just save the class and run.And I believe it must be a standard feature of any serious IDE.
    Thiago,
    I have not used Rational App Developer, but Sun's JVM does not allow any IDE to replace a class in memory whose "shape" has changed.
    If you add a new method to a class in an app that is running in your debug environment, you will have to restart it for your change to take effect.
    Unless the RAD folks have developed their own JVM (they are IBM now and they did it before, so why not!), I don't see how they could provide this functionality.

    There are more details in the Sun bug database.
    Bug ID:4910812-Enhance Hot Code Replacement
  14. Thiago,I have not used Rational App Developer, but Sun's JVM does not allow any IDE to replace a class in memory whose "shape" has changed.

    It uses IBM VM and it does. Now how I don't know, all I know is Ctrl-S -> refresh screen -> there.

    You should try it yourself, there must be a trial version somewhere.
  15. BTW, I do change the "shape" of the class.
  16. I downloaded "Rational Application Developer" and later the "IBM Development Package for Eclipse" and you can indeed change the "shape" of classes at runtime.
    I run into some occasional strange errors trying to debug JBoss apps from Eclipse with the IBM JVM, but it mostly works.
    Thanks for the tip, Thiago!

    Still, I stand by my original criticism of Sun. This is a feature that is long overdue in the Sun JVM. Hooks for scripting languages are nice. Not having to restart an app for simple Java code changes is essential.
  17. I downloaded "Rational Application Developer" and later the "IBM Development Package for Eclipse" and you can indeed change the "shape" of classes at runtime.I run into some occasional strange errors trying to debug JBoss apps from Eclipse with the IBM JVM, but it mostly works.Thanks for the tip, Thiago!Still, I stand by my original criticism of Sun. This is a feature that is long overdue in the Sun JVM. Hooks for scripting languages are nice. Not having to restart an app for simple Java code changes is essential.

    You are welcome. You know, I have the impression some people think that Java is only Sun. IBM's VM is a good example of things people should at least try out to know how it works.

    Maybe if they (Sun) feel a little heat from competition (in terms of VM, because they face it already in other areas) they'll feel a need to improve certain areas.
  18. Python has multiline strings, and so does groovy...

    And how does that help Java? My point was, I think we need multiline string support in Java, so that we can more effectively write embedded scripts and SQL (etc).

    Cheers,
    Clinton