Scripting « Development « Java Articles

Home
Java Articles
1.Build Deploy
2.Class
3.Core Library
4.Data Types
5.Database JDBC
6.Design
7.Development
8.File Input Output
9.Graphics Desktop
10.J2EE Enterprise
11.J2ME Wireless
12.JVM
13.Language
14.Library Product
15.Network
16.Security
17.SOA Web Services
18.Test
19.Web Development
20.XML
Java Articles » Development » Scripting 
Three years ago, I wrote an article for JavaWorld called "Java Scripting Languages: Which Is Right for You?" When I collected the interpreters to compare, I tried to choose ones that seemed a good fit for a demanding commercial application. Ideally, I wanted an interpreter that would ease the extension of the application's user interface, have readable scripting code, be reliable, fast, well-supported, well-documented, and complete. At that time, I narrowed the list down to Jacl, Jython, Rhino, and BeanShell.

Some Java applications' requirements make integration with a scripting language necessary. For example, your users may need to write scripts that drive the application, extend it, or contain loops and other flow-control constructs. In such cases, it's sensible to support a scripting language interpreter that can read user scripts, then run them against your Java application's classes. To accomplish that task, run a Java-based scripting language interpreter in the same JVM as your application.

Emacs is a good example of an application that offers rich support for user scripting. Emacs' approach is to provide services that offer users the ability to custom-create the functionality they need, rather than cramming new features into the tool itself. For example, the Emacs core does not offer Java application compiling/debugging functionality, but through the use of scripts, one can transform Emacs into a powerful IDE. Similarly, scripts can configure Emacs to function as a news reader, email client, and so on. Other good examples of script-supporting applications include such Microsoft products as Microsoft Office and Microsoft Visual Studio.

Until recently only the hardcore were excited about scripting on the Java platform, but that was before Sun boosted the JRE's support for dynamically typed languages like Python, Ruby, and JavaScript. In this two-part excerpt from the forthcoming Scripting in Java: Languages, Frameworks, and Patterns (Addison Wesley Professional, August 2007) Dejan Bosanac narrows in on what differentiates most scripting languages from a programming language like Java, then explains why scripting is a time-worthy addition to your Java programming skillset.

Since I was born and raised on Unix, my head is filled with arcana about various scripting languages I've learned. I've written a lot of useful scripts over the years, some of them quite complex. (I once wrote a compiler-compiler in Perl. Don't ask.) I'd love to be able to use my scripts from Java, but doing so by way of System.runtime() is what I call "3-I": inefficient, inelegant, and icky.

The former second-class citizens of the programming world have leaped to the fore, changing the face of enterprise software development. With the rise of Web 2.0, scripting languages (also called dynamic languages) are now often considered important tools in a developer's arsenal. That's a far cry from than their old reputation as lesser tools for those who can't handle "real" programming.

June 12, 2003 — Sun Microsystems is working with numerous industry partners including Oracle, Macromedia, and Zend Technologies to support the use of scripting languages in its Java platform.

In Part 1 of this series, I introduced JudoScript, detailed its JDBC (Java Database Connectivity) scripting abilities, and demonstrated the power of its synergy of functional support on top of a general programming language engine. JudoScript is, in a way, a shell for the underlying Java platform, which is, in turn, an interface to today's computing environment that is much richer than 20 or even 10 years ago. JudoScript is designed for today's computing needs, and is a language designed for any computer developer, not just Java developers, to manipulate computers and information.

Lynn Greiner's article on the state of the scripting universe was slashdotted. Several people raised their eyebrows at the (to them) obvious omissions, since the article only covered PHP, Perl, Python, Ruby, Tcl and JavaScript. As I wrote at the time, Lynn chose those languages because hers was a follow-up to an article from three years back. Plus, most IT managers are familiar with at least one of those well-known scripting languages, even if they haven't personally written a line of code in one of them.

JDBC (Java Database Connectivity) is a standard Java API for SQL database accesses. What does JDBC scripting mean? It means using JDBC for manipulating SQL databases in a way comparable to and beyond what native database clients do. JDBC scripting is an attractive, practical matter, because SQL databases are and will be the dominant data sources in any enterprise system. It is also important to note that all major RDBMS (relational database management system) vendors provide pure-Java JDBC drivers for their own products, so a capable JDBC scripting tool can easily take advantage of that capability. All you need is a JDBC URL and the JDBC driver jar file in the classpath. You can connect to multiple databases simultaneously for multisource, heterogeneous data processing.

Before we look at the JSR 223 interfaces and this article's implementations of them, I'd like to point out that though the name of the JSR and the title of this article both contain the word scripting, that's not to say there needs to be limitations on the languages that can be integrated with Java the JSR 223 way. You can take any language you fancy and wrap it with a layer that conforms to the contract laid out in JSR 223. The language can be object-oriented, functional, or in any other programming paradigm. It can be strongly typed, weakly typed, or not typed at all. In fact, before writing this article, I had implemented a JSR 223 wrapper for Scheme, a weakly typed, functional programming language, and put it up on SourceForge. For this article, however, we look at a much simpler language so we can stay focused on the topic of JSR 223 without the details of a complex language overwhelming us.

There is nothing to restrict the use of a dynamic (scripting) language on the virtual machines designed for languages such as Java and C#. As long as we implement the compiler appropriate for the target virtual machine's intermediate bytecode, we will receive all the features of the scripting language in this environment. Doing this, we could benefit from the strengths of both the system-programming approach of Java, and the scripting programming model in our software development process.

It has recently become popular to differentiate between the Java platform and the Java language, but many Java developers still are unsure of how to incorporate scripting into Java application development. In this article, Gregor Roth introduces you to scripting on the Java platform. Learn when and how to use scripts in your Java applications, whether you are gluing together various Java application modules with Groovy or Jython, or writing your first JRuby-based application for the Java platform.

The latest major Java release (Java SE 6, aka Mustang), is now in its beta version. Although this new version is not as major an update as Java 5, it does come with a few interesting new features. Undoubtedly, one of these is its support for scripting languages.

Jython is a complete re-implementation of the Python programming language, written in 100 percent pure Java, which runs on any Java Virtual Machine (JVM). Python is a high-level, interpreted, object-oriented scripting language which combines elegant syntax rules with powerful built-in objects to create a language that is very easy to write, read, and maintain. Python is perhaps most notorious for its use of indentation to mark the beginning and end of statement blocks.

XML is increasingly used to store data in Java applications. This article describes how XML can be extended to incorporate behavior, using the author's open source scripting language Simkin.

It is easy to get trapped in this sort of loop. You create incremental fixes to your current problems and forget to stand back and take another look from the broader perspective. Fortunately for those of us working on this particular project, a few forward-thinking team members pointed out that we were creating an entire language in XML and suggested that we move to a full-blown scripting language like Jython. That way, all of the scooping, variable passing, and other programmatic constructs could be handled by language experts, and we could spend our time writing the testing system instead of a proprietary XML-based language.

The JavascriptFrame implements SimFrame and allocates the scripting manager and engine in the constructor, just like our simple example earlier. Whenever initParticle is called by the simulator, the JavascriptFrame will execute the contents of the init text area, which contains the code that the user typed into the top editor of the application. It'll do the same for updateParticle and drawParticle, except using the code from the other two text areas.

One of the exciting new features of Java Standard Edition 6 will allow the tight integration of Java and scripting languages through a standard Java Scripting API. In this article I will take a closer look at how the current Mustang beta implements the underlying JSR-223 (Scripting for the Java Platform) and introduce you to its classes and interfaces. We will, however, concentrate on client-side scripting. Web scripting, which is also described in JSR-223, might be subject of a later article.

The Hecl Programming Language is a high-level, open source scripting language implemented in Java. It is intended to be small, extensible, extremely flexible, and easy to learn and use. Infact, it's small enough that it runs on J2ME-enabled cell phones! David Welton, Hecl project owner, gives us a full view of this scripting language.

The ideal balance would be to have the flexibility of dynamic languages in the development phase, and pure Java performance in production. Fortunately, most of the scripting languages provide mechanisms that could be used to achieve this goal. The main one is the ability to compile your scripts to Java classes. After this process, you can use them to instantiate regular Java objects. Most of the "modern" script engines provide this functionality, but some of them (such as Groovy) go even a step further and define Ant tasks or Maven plugins that could be used in your build process.

Learning Curve Journals, Part 1: Exploring JavaFX Script JavaFX Script is Sun Microsystem's new scripting language. This series of technical articles follows a developer as he learns the technology. (August 2007)

Have an opinion about scripting languages in Java and the BeanShell? Discuss this article in the Articles Forum topic, Scripting Java: The BeanShell JSR.

The javax.script package added to Java SE 6 makes integrating dynamic languages easier. It provides a single, simple way to invoke dozens of scripting languages using a small set of interfaces and concrete classes. But the Java scripting API is about more than making it easier to script parts of an application; the scripting package lets you read and invoke external scripts at run time, which means you can alter those scripts dynamically to change a running application's behavior.

Most Web sites today add dynamic content to a Web page making the experience for the user more enjoyable. Dynamic content is content generated by some server process, which when delivered can behave and display differently to the user depending upon their settings and needs. Dynamic Web sites have a threat that static Web sites don't, called "cross-site scripting," also known as "XSS."

The Java scripting API added to Java SE 6 provides a unified way to run ? and share code and data with ? external programs written in a variety of dynamic languages. Augmenting a Java application with the power and flexibility of a scripting language is especially useful when the scripting language can perform a job more clearly, simply, or concisely. But the Java scripting API doesn't just allow dozens of scripting languages to be added to a Java program in a unified way: It also allows scripts to be located, read, and executed at run time. These dynamic capabilities let you alter scripts to change an application's logic while the program is running. This article demonstrates how you can use the Java scripting API to invoke external scripts to alter a program's logic dynamically. It also looks at issues you might face when integrating one or more scripting languages into a Java application.

I dislike the term "smell" when it comes to describing something like code. It feels strange to speak anthropomorphically about bits and bytes. It's not that the word "smell" doesn't accurately reflect a symptom that indicates that code may be wrong, it just sounds funny to me. Yet, I am choosing to perpetuate my vexation to describe software builds because, frankly, many build scripts I've seen over the years stink.

Reduce system events handled by administrators by 25 percent : In this real-world case study, Singlestep Technologies, a company that develops software to help its customers manage IT infrastructure, incorporated the IBM Autonomic Management Engine (AME) into its Unity Suite to help pinpoint system anomalies faster. The AME (which uses the Common Base Events format) helped the Singlestep suite reduce user meantime to identification of system problems and created a 25 percent reduction in the number of events the operations engineers had to address.

In practice, Simkin encourages you to insert scripts in the middle of XML data files -- for example, the e-mail address of a user and a script describing what to do with the e-mail. For more technical details on Simkin, refer to Simkin: A Scripting Language for XML.

Simkin is an attractive idea: It combines a simple scripting language with XML. Use it to create more flexible applications that can be reconfigured, or extended, through XML files.

When faced with a new engineering project or task, one of the first questions to cross a developer's mind is often "What language am I going to write this in?" Sometimes Java seems like overkill; we'd like to throw together something quick and dirty, and it might be nice to do interactive development. Typically in such situations, developers prefer Perl, Python, or even Tcl. However, there is a large array of new, neat scripting languages built to take advantage of the Java virtual machine that might be able to better serve your needs than one of those old workhorses. In this article, we're going to look at a few of the more interesting Java scripting languages currently available.

The vulnerability itself, CERT Advisory 2000-02, sometimes called cross-site scripting or malicious tagging, takes advantage of dynamically generated Web pages. Basically, a malicious script, which could be written in a number of different languages, can be inserted as input into dynamically generated Web pages. Unless the pages are specifically built to protect against the insertions of these scripts, they allow an attacker to insert code that can poison cookies, expose SSL connections, access restricted sites, or pull off a number of other attacks.

In part one of this article: Scripting in and around Java , we introduced a large number of scripting languages based on the Java platform. We found that some were implementations or hybrids of existing scripting languages, some were created to script regular Java code, and others were new languages in their own right. In this part, we take a closer look at two of the scripting languages introduced previously, Compaq's Web Language (formerly known as WebL) and JPython. We'll explore these languages more closely and include some example code that show off language features and capabilities.

Welcome to the final installment in a three-part series that explores some of the new features in Java Standard Edition 6. If you recall, the first part focused on enhancements to the Collections API; the second part toured the new Scripting API. Because I'm not finished with the Scripting API, Part 3 introduces you to my miniature expression language and shows you how to implement a script engine for this language.

w__w__w.___j___a_va2__s___.c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.