Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can, or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing heavily in Java's future as a platform for platforms

Also see:

Discuss: Tim Bray on 'What Sun Should Do'

Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Scripting power saves the day for your Java apps

Improve your user's satisfaction with support for user-defined scripting in your Java applications

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
The developers of today's software products must face some hard realities. There is increasing demand for new features from users, and increasing pressure on vendors to develop products in ever-shorter timeframes. Demands for features also tend to be widely varied and unique, making it nearly impossible to satisfy all users just by adding a fixed list of new capabilities to a piece of software. A typical user will have repetitive tasks that an easy-to-create macro can automate. Moreover, some tasks are inherently complex in nature, and in such a situation, wizard-like guidance in simplifying the task can be helpful.

Most applications today, including Java applications, attempt to satisfy user needs by adding newer functionality to successive versions. With this approach, users are forced to wait for the next product release for their needs to be met -- while their customization needs remain unfulfilled even with newer versions.

If a software tool could allow users to interact with it through user-written scripts, the value of the tool would improve tremendously. Using scripts, users could ease their routine tasks by writing macros, by creating wizard-like functionality to ease complex operations, and by modifying the behavior of the tool to suit their needs. How many Java applications provide such support?

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.

These applications provide rich services and support for user scripting. By providing hooks into an application, we can transform it into an environment. User scripts use service provided by such an environment to write their applications.

In this article, we'll look at a way to infuse applications with scripting support. For that purpose, we'll first write a simple application without scripting support, then incorporate such support into it. This two-step approach demonstrates how to add scripting support to (relatively!) long-standing Java applications. We will also develop a framework for scripting support, which makes support for a new scripting language, or change to a language's interpreter, a simple task.

An application without scripting support

First, let's develop a simple application designed without a scripting extension in mind. For this purpose, we'll develop a very simple drawing application that can draw shapes on a drawing surface -- a trimmed-down version of a typical CAD tool. And since there's no point to using object-oriented design and Java if we can't reuse existing components, we're going to use the slate component developed in "Java Tip 75: Use nested classes for better organization" as the basic building block for our application.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources