Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Create a native Java executable, revisited

You can create a native executable -- but do you really want to?

  • Print
  • Feedback

Q If I know the operating system on which my program will run, can I compile my Java code into native machine code and run it without the VM?

AYes, it is possible to compile Java code into native code. To do so, you will need a native compiler. VisualAge for Java and Visual Café ship with high-performance native compilers. Unfortunately, the JDK does not ship with native compilers, and I am not familiar with any that are freely available. There are some freely available Java-to-C compilers, however.

URLs for various native compilers and C translators can be found in the Resources section below.

Be warned, though: you may lose certain features of the Java platform if you compile to native code. Further, some of the older compilers will not allow the dynamic addition of new classes at runtime. When choosing a compiler, carefully compare the compiler's feature list against your software's requirements, as expected JVM behaviors and features may not carry over to the compiled code. Native compilers can also be expensive. If you are concerned about performance, adaptive compiling technologies such as HotSpot and JIT have improved Java performance greatly. Happily, they keep getting better. If your intention is to simplify the user experience by not requiring the user to type java <class name> at the command line, you can simply create a .bat file for Windows or a shell script for Unix that takes care of setting CLASSPATHs and running the program. A batch file could be as simple as:

run_that_program.bat
java program_class_name


  • Print
  • Feedback