native compiler : Java Glossary
©1996-2017 Roedy Green of Canadian Mind Products
- native compiler
aka AOT (Ahead Of Time).
Compilers that compile to native code before they are shipped to the customer. More
usually called native compilers. Most compilers generate
JVM (Java Virtual Machine) byte codes. Native Code Compilers generate native
*.exe files. JITs (Just In Times)
create native code at execute time, but don’t create *.exe Examples are JET and
gcj. There are eight ways to get what acts like
a *.exe file without using a true native compiler using some
sort of executable wrapper.
Advantages of Native Compilation
What are the advantages of a
Visit any of the vendor sites, such as JET for independent benchmarks. The improvement is even more
marked for old clunker machines that your customers may use. Native compilations
tend to me more scalable, doing well as you add more threads. Depending on just
what you are doing, you may get over twice the speed of Java Hotspot.
A natively compiled program will load and start execution much
faster than one using Java JVM.
Customers resent slow load times even more than slow execution times. They have
nothing to do but sit there and wait. JITed Java is precluded from many
applications because of its extraordinarily slow load time. Natively compiled
Java opens the doors to all the traditional C applications.
Java version 1.5 or later load time are vastly
improved and so the need to convert jars to native code is much less pressing
than in past.
Self-Contained Distribution Package
Java, or even Java Web Start requires
the customer to pre-install the JRE (Java Runtime Environment).
You may not be legally permitted to bundle that JRE
with your app. You are most certainly not permitted to strip out the parts your
app does not need. The customer has to go get and install the
himself. Native apps can be distributed in familiar ways as totally
self-contained packages. On the other hand, once Java Web Start is installed, the
end user can install new apps with a single click.
Java class files are quite tiny, but they need the
entire JRE to make them work. If the customer has Java
already installed, then the class files packed in a jar are exceedingly compact.
However, if he does not have Java installed, that then the native distribution
will be smaller than distributing tradiditional class files plus a
Native apps, especially optimised apps, are much harder to
decompile (reverse engineer).
The customer need not know your app is written in Java. Some customers are Microsoft fanatics who follow the
party line that Java is slow or evil.
Compilers like JET,
bundle classes into DLLs (Dynamic Link Libraries). This means if you
have two JVMs (Java Virtual Machines)
running, you need only one copy of the DLL (Dynamic Link Library)
in RAM (Random Access Memory). This makes more efficient use of
Disadvantages of Native Compilation
What are the
disadvantages of a native compiler:
Your code works on only one platform. Even if you buy a
multiplatform compiler, you need to generate different versions, one for each
platform and different install scripts for each platform. It is even more import
than ever to test the code on each platform.
The compiler is an extra cost item.
Distribution is more complex with DLLs
and EXEs and an install script. (JET comes
with an install generator, so you don’t necessarily have to buy
Installshield or equivalent.)
DLL version hell
In place of the problem of mixed
generations of JRE, you have the problem of mixed generations of
on your client site.
Native compilation is more complex than standard
compilation. You need to learn new skills to master it, e.g. dealing with a
mixture of static and dynamic class loading. It is quite simple. The only mildly
complicated thing is dealing with dynamic class loading.
You can’t use native compilers on Applets. In theory you could compile your app as a
DLL and make
pure java hooks into it. You would have to design your app as a dll, sign it,
arrange for installation of the DLL.
The game is hardly worth the candle.
Java Web Start
You can use native compilers with Java Web Start Weblets, but only after unpacking jars,
bypassing security restrictions and execing the native exe.
native code projects have been abandoned. TowerJ and Webgain
Café are defunct. Supercede was sold to
Jove, who went out of the business. I have
heard nothing of BulletTrain. I
don’t think IBM (International Business Machines)
with Visual Age or JBuilder may have bundlers, but not native code generators.
So left standing are:
Excelsior JET and gcj.