Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

The Win32-Java hybrid

Worried that your Java apps won't run on Windows? Here's a strategy that blends the best of Java with Win32 to create applications that run on Microsoft OSs

While you're waiting for Microsoft to reveal its future strategy for Java on various Windows platforms (if there is one), you can take advantage of a Windows application development solution that blends Win32 and Java technologies into a single, cohesive unit. This Win32-Java hybrid (WJH) solution makes it possible to quickly create interesting and robust Windows applications, such as a smart card-based security system.

Win32 is Microsoft's architecture for its 32-bit operating systems. Win32 includes a collection of APIs (application programming interfaces) that Windows applications can call during their execution lifetimes. These applications are written in languages such as C, C++, or Visual Basic, and then compiled into executable code which is stored in DLL or EXE files.

The structure of a WJH application is illustrated in Figure 1.

Figure 1. WJH application structure

The red arrows indicate the composition of a WJH application -- a Win32 executable and at least one Java class file. The Win32 executable, among other things, loads the Java virtual machine (JVM) DLL and creates an instance of the virtual machine. The starting Java class file and its main method are identified. This information and its associated command-line arguments are passed to the JVM. The JVM then loads this class file and interprets the instructions located in the file. To assist it in carrying out these instructions, the JVM may call Win32 API functionality or JVM Win32 DLLs that support the JVM.

The idea behind the WJH is to write a small amount of code in C or C++ (the Win32 JVM launcher) and to write most of the code (the application portion) in Java. So what is to be gained by using the WJH approach over the more conventional Win32, C/C++, or Visual Basic approaches? Table 1 lists some advantages.

Table 1. Advantages of the WJH approach


The WJH advantage Description
Simplicity The Java language avoids the more complex language features that are found in C++. These features include multiple inheritance, destructors, and operator overloading (Java offers a feature known as an interface to offset its lack of multiple inheritance). Java's simplicity results in a shorter learning curve.
Reliability The Java language does not support the concept of pointers. The misuse of this language feature often results in program crashes or malicious behavior. Java was designed to be reliable and secure.
Wide variety of free APIs Sun has released a wide variety of free APIs for Java. These APIs are designed to offer current Win32, Unix, and other OS functionality from a portable point of view.

For all its advantages, Java has one significant disadvantage -- performance. Virtual machines slow performance. However, the advent of the just-in-time compiler (that part of the JVM which compiles Java instructions -- known as bytecode -- into native machine instructions during execution) is fast causing the performance issue to disappear.

So, how do we create a WJH application? The best way to answer that question is to study an example. To that end, I'm presenting a text editor application that is partly written in C (I didn't need C++ for this application) and mostly written in Java.

1 | 2 | 3 |  Next >
Resources