By Kevin Yank

Write Java Web Apps in Visual Basic (or JavaScript!)

By Kevin Yank

More from the JavaOne 2006 keynotes

One of the new key features in Java 6 (Mustang), available now in beta and weekly snapshots and slated for release in October, is support for alternative languages running on the JVM. In particular, Java 6 will ship with support for running JavaScript code as a first-class citizen, with complete access to the Java class libraries and the ability to call back and forth between Java and JavaScript code within a single application.

At JavaOne on Tuesday, Sun took the wraps off of two new projects that are taking advantage of this capability in a way that will be of interest to web developers. The first, Project Semplice, brings the Visual Basic language to the Java platform. Not meant for porting existing VB apps over to Java, but rather for allowing Visual Basic developers to transition to the Java platform while leveraging their existing skills, Semplice lets you write code using VB syntax (including all the automatic type conversion, support for properties implemented by methods, and other niceties that VB developers love so much) that compiles to Java classes that will run on the Java 6 VM. As J# is to Java, Semplice is to Visual Basic.

In the demo during the keynote, Semplice developer Tor Norbye (regular on the Java Posse podcast) demonstrated building a simple web application in VB using a pre-release version Java Studio Creator. Starting from a blank page, he dragged a number of JavaServer Faces (JSF) components onto the page, then double-clicked one to add an event handler to it. The editor that popped open contained a new event handler written in Visual Basic, to which he quickly added some simple implementation code, then compiled and ran the application.

The application, he pointed out, made use of JSF components written in Java, and he accessed properties of these directly from his Visual Basic code. Additionally, the JSF components call the Visual Basic event handling code from within Java. Semplice allows these two languages to work together transparently.

Thanks to features of the VB language, instead of having to call farenheit.getText() to obtain the value of the farenheit form field, he could refer to it as farenheit.Text, or even just as farenheit, thanks to Visual Basic’s flexibility. He was also able to use the resulting String value in an arithmetic calculation (i.e. celsius = (farenheit - 32) * 5 / 9) without having to convert it to an integer.

For developers that want the power of Java when writing server-side business logic, but want a more flexible and loosely-typed language when writing web presentation logic, Visual Basic running on the Java VM could well be a very attractive option!

Even more flexible than Visual Basic, however, and likely much more familiar to them as well is JavaScript. So why not write the server-side code of web applications in JavaScript? That’s exactly what Project Phobos will do. With Project Phobos, you can either write server-side application logic with JavaScript directly within your HTML templates (much like you can in PHP or JSP), or in separate “helper” scripts to keep your code separate from your markup.

Along with the many other projects working to bring other languages to the Java VM, these two projects give developers even more choices when considering Java as a web development platform.

The video of both demos may be found in Segment Three of the Sun Technical General Session: Java Platform Roadmaps: The Big Stuff, Today & Tomorrow from Day 1 of the JavaOne 2006 conference.

Full details and screenshots of Semplice in action on project developer “HerbertC”‘s blog.

  • hrmm so maybe those .NET guys were onto something?

    So like all applications grow until they can check your email, do all languages evolve to include Javascript? Wait, but they’re not languages anymore are they. This is where the marketing gets confusing. Java 6 ™ refers to both the language, the JVM and the tools. Either way, it’s great news for the Java platform!

    Did you pick up on how open and/or difficult it will be for other’s to implement additional language support? (Ruby, Python *hint hint*)

  • Ruby and Python are already happening on the Java platform in the form of JRuby and Jython, but much of the focus for Java 6 and Java 7 will indeed be on making it easier to bring dynamic and alternative languages to the JVM.

  • Aren’t JRuby and Jython implemented through JNI? I’m guessing anything they’re proposing will be more fun than that…

  • Both projects are written in 100% pure Java. No JNI.

    The downside of this is that both projects are subject to a few limitations. JRuby cannot load Ruby native shared libraries written in C. Likewise, Jython doesn’t support a number of Pyhton’s built-in modules that access native OS functionality.

    From what I’ve read, however, the biggest problems faced by these projects is performance, not obscure bits of missing functionality, and that’s because these projects are really just scripting language interpreters written in Java.

    Sun’s recent initiatives like Semplice and Phobos are entirely different beasts, bringing the scripting language closer to the VM. Semplice appears to be compiling VB syntax directly to Java bytecode, while Phobos makes use of Mozilla’s Rhino JavaScript engine, which is included in Mustang.

    Java 7 is slated to actually extend Java bytecode with operations required to support dynamic languages like Ruby and Python running directly on the VM.

  • vishal

    i would like to know how to embed javascript code block in c#
    thnx and rgds

  • Eclipse Magazine

    My colleague at work pointed me to this excellent new resource for the Eclipse community: Thought I should spread the word for the benefit of the larger community.

    They also released a new monthly monthly digital magazine for the Eclipse ecosystem. It’s available as a FREE download (infact four of the upcoming issues are available for FREE), so grab your copy now:,id,4,nodeid,6.html

    I also noticed a wonderful promotion for folks wanting to share Eclipse information for the benefit of the larger community. Have a look:,id,16,nodeid,4.html.

Get the latest in Java, once a week, for free.