All | BASIC | Personal | Sun
« Previous day (May 18, 2006) | Main | Next day (May 20, 2006) »
20060519 Friday May 19, 2006

Project Semplice - Visual Basic for the Java Platform Yesterday we - that is Tor Norbye, John "Get a blog" Kline and I - presented our project at JavaOne in session TS-3576 under the deceptively unexciting title "Visual Basic and the Java Platform". Well, it actually is "Visual Basic for the Java Platform"!

We are in the early stages of development for a compiler and tools for writing Visual Basic (VB) programs for the Java Platform. That means we will compile VB source code into Java class files that will run on the Java Virtual Machine. Even better, you will be able to import existing VB6 applications into any of the Netbeans family of tools and continue to work on them. Of course I must add a word of caution at this point. If your existing VB6 application contains any calls to the Windows 32 API, we will not be able to emulate all these entry points. We will also not be able to handle any OCX controls that you don't have the sources for. That said, let me show you some of the stuff we demoed yesterday in our session. The slides of the session are also available on the JavaOne website.

Importing and Maintaining an Existing VB6 Application
Our first demo was to import one of the sample applications that comes with VB. We imported the Calculator project, compiled and ran it. Next we made a modification to the Calculator by changing the 'X' character on the button for the multiplication operator to the '*' character. This also required a modification to the source code as well because it checks for 'X' and now needed to check for '*'. We then recompiled and ran the Calculator again and voila, we could use '*' as the multiplication operator!

Creating an new VB Application from Scratch
The next demo was to write a Celsius to Fahrenheit temperature conversion application from scratch. We used the Netbeans GUI builder to create the form and then added an event handler for the conversion button. In the event handler, we take the contents of the Celsius textbox, apply the conversion formula and output the result into the Fahrenheit label. Note that in Basic you do not need to worry about type conversions as you need to in Java. Note also that we are taking advantage of default properties in this example.

Creating an new VB Application that interfaces with a Java Class
An important thing for us is to allow VB programmers access to the all the existing Java Beans and libraries. Therefore, we wrote a VB application that called a Java class for our next example. The application finds all prime numbers in the range from 1 to 8192 using the Sieve algorithm by Eratosthenes. The application has a UI written in VB from which we can call the Java version of the algorithm as well as a VB version of the same algorithm. Note that the runtime of the Java version is slightly faster because the VB version uses non-zero-based arrays, which causes a slight overhead at execution time. We will try to make some improvements here in the future. Disregarding the aforementioned non-zero-based arrays, the performance for VB compiled and Java compiled applications is very similar.

Calling VB Classes from a Java Application
In the previous example, we showed how to call into Java classes from a VB application. In the next example, we will call a VB class from a Java application. We will take the Sieve algorithm again, except this time we are writing a Java UI and call the Java version and the VB version from there. Also this time we are going to deploy the application to the SavaJe Jasper S20 cell phone. Yes, that means that VB is running on a cell phone! Note again that the VB version of the algorithm is slower because of non-zero-based arrays.

A Fractal Application
For our last demo we downloaded a VB application that computes a fractal (similar to the famous Mandelbrot fractal). We also obtained a version of the example that was compiled into native code with the VB6 compiler. As you can see in the screenshot (the upper left corner of the fractal shows a label with the time it took to compute the fractal), the Java version performs significantly better than the natively compiled original. Be aware though that a performance of this magnitude cannot be expected for all applications.

What's next?
We would like to hear from you! Is this a project that you could use, either yourself or in your company? Do you prefer VB6 or VB.Net? Are there any extensions to the VB language you would like to see?

Looking forward to your comments and happy programming!

Technorati Tags: , , , ,

Posted by herbertc ( May 19 2006, 01:55:00 PM PDT ) Permalink Comments [72]

HerbertC's Blog






Calendar

RSS Feeds

Search

Links

Navigation

Referers