During this year's JavaOne conference, it seemed as if Sun Microsystems executives finally understood the popularity of scripting languages ' a popularity company officials had acknowledged only grudgingly in the past. In fact, during the show, the company introduced a scripting language of its own, a multimedia authoring tool called JavaFX.'Why another scripting language? The world has so many,' asked Java creator James Gosling, prefacing the JavaFX announcement. Indeed, there are many languages. Thanks to the proliferation of Web applications, the past decade has seen an explosion in scripting languages, such as Perl, Python, Ruby on Rails and PHP.Such scripting languages do not have the formal restrictions of regular languages, allowing programmers to get up to speed more quickly. Although mostly relegated to smaller tasks, they have been taking on more complex duties that previously would have been relegated to enterprise Java platforms.Now, the folks who develop the Java platform, called the Java Virtual Machine, have engineered it so it can run some of these scripting languages. They are also working on ways to allow non-Java programs to use functions originally written in Java. Industry observers say it represents a long-term shift in thinking.Initially, the developers behind Java 'were very cold to the idea of [outside] languages running over the JVM,' said Frank Cohen, head of service-oriented architecture test automation company PushToTest. 'Over the last two years, [Sun] has accepted scripting languages and has even encouraged people to write scripting languages to go on top of the JVM.''We unfortunately created a strong association between the Java language and the Java platform,' said Sun Microsystems technical evangelist Raghavan Srinivas in his presentation at Sun Tech Days recently in Washington. 'But there is no need to have this association be very close. You should be able to run non-Java programs on the Java Virtual Machine.'By giving Java programmers more options about what language to use, they can gain more flexibility within their preferred development environment. And by opening the JVM to other languages, non-Java developers can use the rich set of Java functions.Historically, Sun has positioned Java as a cross-platform language. The idea was that a programmer only had to write one set of code, which then could run on a variety of platforms such as Unix or Microsoft Windows. The JVM made this possible, as Sun itself built a unique JVM for each operating system. So all the programmer had to do was write for the one JVM, rather than for multiple OSes, which simplified a lot of work.As Srinivas noted, the JVM doesn't necessarily have to run Java alone ' a fact that the developers around the JVM are starting to acknowledge. The Java community has been working to accommodate scripting languages of late. Sun established the Java Community Process to allow vendor input to updating Java specifications, so development of the language and platform is done by a mix of Sun employees and outside contributors. JCP has written a number of specifications that will allow Java to interoperate with other languages.Java Specification Request 223, which is now undergoing final release, details how scripting languages such as PHP can call Java objects, or small pieces of Java programs that execute certain tasks. This will allow developers to make use of features previously only available to other Java programs.JSR 223 also details how scripting languages can be used within Java applications run from within a Java-based application server. This lets Java Web application developers harness non-Java scripts.Another specification request, JSR 282, which is not as far along as 223, details how to support dynamically typed languages on the JVM.Features within this specification are slated to be included in the upcoming Version 7 of the Java Standard Edition.In this case, the Standard Edition will let developers add support for languages by simply dropping the Java Archive files on the computer in a location that can be found by the JVM. When the Java program runs, it looks for the scripting engine and then uses that to run the script itself. The programmer can modify existing languages or even write one entirely from scratch.Since Java is a fairly mature language ' with supporting libraries and a solid runtime platform ' why should hard-core Java programmers look to scripting languages? 'It's just easy to program in scripting,' Srinivas said. 'It is really good for rapid prototyping. [Scripting languages] are really good if you are doing small projects.'Perhaps the feature that best eases a programmer's duties ' one that most scripting languages possess ' is something called dynamic typing. This means programmers do not have to specify the formats of the information entered into their programs ahead of time.It is the opposite of static typing, which requires that inputs be in a certain format defined by a programmer. They have to specify if an input has to be, say, a string of characters of a certain length, or a number with so many decimal points. Then, if the input ' perhaps entered by a person or another program ' is not in that format, the program will send out an alert or even halt.Most programming languages such as Java are statically typed. Although this ensures the program runs more smoothly and has fewer security vulnerabilities, defining each variable at development time can be time-consuming.Another advantage of scripting languages, Cohen said, is that they allow organizations to very easily create domain-specific languages, or languages customized to answer one specific set of needs. These languages can have very narrow uses, such as for installing new programs across a set of servers. Since the administrators don't have to learn an entire regular programming language to use these tools with dexterity, they can work more easily in a very tightly defined subset. Plus, it is easier to maintain that language over time, Cohen said.'One of the things that is charming about scripting languages is that they tend to be focused on specific things,' Gosling said during his presentation.By enabling JVM to support scripting languages, the Java team can ensure that Java programmers can make use of these flexible features without having to learn entirely new languages. In addition, they can still use the vast array of Java libraries to take care of routine tasks instead of writing the functions by hand.Opening up the JVM to outside languages also could result in a potentially wider audience. 'There are more non-Java programmers out there than Java programmers,' Cohen said.Support for new features such as dynamic typing was hard for the JVM development team to incorporate, said Bob Brewin, Sun's chief technology officer for software, in a conference during JavaOne. 'Interpreting a dynamic language is difficult.There's a certain amount of bookkeeping that the [program] requires to dispatch a method call.' But JCP seems determined to carry out the duties.Although the Java environment has only recently been laid open for interaction with scripting language, an amazing number of new dynamic languages have already sprouted up, including Groovy, JRuby, Beanshell, Jackl, Jaskell, Jawk, Jelly and Jexl.Many of these new languages are very similar to existing languages, but they are written in the Java environment. Jython, for instance, is a version of Python written in Java, which lets developers easily import Java classes (GCN.com/786).And Sun itself even got into the game with JavaFX.In a way, JavaFX is a domain-specific language, one designed for building multimedia-heavy Web sites more easily than by using Java alone, said Rich Green, Sun vice president of software, in a presentation on the language. That market is now dominated by Adobe Flash.Although the company has long offered this capability through Java Applets, Green said Sun had heard many complaints about the complexity of deploying Java, noting that while the language is flexible it is also burdensome for the Web.'We can do it with Java, it just takes a long time,' he said, summing up the concerns the company received from developers.JavaFX is intended to offer a simple set of interfaces allowing Web developers to harness the wide range of Java libraries, particularly Java Swing and Java 2D, said Chris Oliver, one of the Sun developers behind JavaFX, in a follow-on presentation. In doing so, developers could create interactive buttons, sliders and special effects in far fewer number of lines than they could using Java alone.JavaFX scripts can run on any machine with the Java Standard Edition, which is deployed on most user desktops today. It can also be used on portable devices, allowing developers to create one Web application for multiple platforms.Although Sun Microsystems is branching out from Java, this doesn't mean its support for the language will diminish, company executives say. 'We still believe that Java is the best language for robust, maintainable applications,' Brewin said. It just means that Java will have some help from its kin.And that can only be good news for developers.
NEW HORIZONS: Sun's Bob Brewin says Java still is best for robust applications.
Write once, run everywhereThe dynamic typeEasy action