Hi,
[*] Compiling into native code destroys portability, which is one of
the main benefits of Java. If you want to create a native executable
because you wanted to make it easy to distribute and use programs,
consider a Jar file instead.
Some companies make products that do this. See the webpages for
Symantec http://www.symantec.com, Supercede http://www.supercede.com,
and Tower Technology http://www.twr.com. The first two are targeted to
Windows. Tower Technology supports several flavors of Unix.
Also, there is a native Java compiler from IBM, known as the HPJ (High
Performance Java) compiler. One user has reported that it created a 2Mb
executable from a 12K java file, and did not run any faster. See
http://www.alphaworks.ibm.com/
See also Instantiations JOVE http://www.instantiations.com/jove.htm,
the paper about the Toba project
http://research.microsoft.com/research/lt/toddpro/papers/coots97.pdf,
Network World, "Vendors Rush To Speed Java Performance", Feb 9 1998, at
http://www.nwfusion.com/news/0209java.html
Compiling to native code takes away the most significant benefit of
Java: portability of executables. Further, if you want your Java DLL
(or .exe) to interact with C++, you'll have to specify which specific
C++ compiler and/or actually compile some sort of linkage via the
appropriate C++ compiler. C++ does not have a standard ABI, so there is
a big problem with interoperability. Every C++ compiler uses a
different object model, a different way of laying out class members,
and a different way of "mangling" names for the linker.
C is much simpler. The only question here is how structures are
"packed" (i.e., are integers aligned on four-byte bounds?). All the C++
compilers can interact with C code, thanks to 'extern "C"'
declarations.
Consider carefully why you want to compile to a native executable, and
whether there is a Java way to accomplish your goal. There may be a
good reason for compiling to native code, but it needs to be thought
through.
Thanks,
Senthilkumar
You can give GCJ (GNU Compiler for Java) a try.
From their Web page (http://gcc.gnu.org/java/index.html):
=================
What is GCJ?
GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile:
Java source code directly to native machine code,
Java source code to Java bytecode (class files),
and Java bytecode to native machine code.
The whole purpose of the "Java to Native Code" or better yet "Java to C" movement is extremely simple.
Java has the cleanest syntax of any language written yet, and its integrated IDE capabilities are fantastic, however, the JVM (SSSLLLLOOOWWW) completely limits java to a very very small subset of systems.
Otherwise I guarentee, every single major application out there right now would be being done in Java pure and simple, this includes games, and mission critical applications. People would absolutely flock to this language.
With a java to C compiler, people could then recompile the c Code into their platform specific application easy enough, and have the shortest development time for a program imaginable, without the major setback of the JVM.
One more thing, please remember most applications are absolutely NOT internet based, or even networked.
Sun wants to keep java theirs for one reason, the licensing fee. If they make everyone use the JVM. They must license the JVM, otherwise, if they made a true Java to C compiler they would not be able to find out what applications were being done using the Java Language. This is also why I believe they are afraid of putting it to a standards commitee.
However, the idea that a language as a platform is really a bad idea. You are not pigeon-holing the consumer here, but rather the developers, and most of them say "why bother". With C# comming too, I can only hope that they have recieved the message, otherwise independant developers will have to start making there own languages, or brush up on c++ or pascal to get their work done, since these are non licensed languages.
One other note, all of the open source Java 2 c compilers are for only those classes that are non graphical, this includes the gnj or whatever.
Window based programming is is also the strongest part of java. the comparative c or c++ code to do any of the non window (GUI) based programming is extremely simple, and the question arises again, why bother with java? You are hit with the JVM penalty for processes that have almost the same syntax in c++ for no reason. And standard c code will be able to be compiled to different platforms without a huge amount of restructuring.
It is in the windowing interface through awt and Swing where java becomes a real tempation to use.
However, with the introduction of C#, this tempation starts to go away rapidly, and rapid windows based multithreaded applications that use a jvm and a much faster windowing system will be available with c#. Of course, this also brings the same question to microsoft as to when they will make a native code compiler for c#? However, they have usually listened to developers and created standardized windows based API's for easier development for their platform, ala the "Direct everything" API's. So, I am confident that they will make a native compiler for their classes.
Why can't sun?
The reason why I want to make native win32 code is so that my programs can be used on other computers, by people who aren't into programming. They don't have the JDK installed and don't want to install anything on their computer.
I've used JET(personal), it works but it still needs the JDK.
I've been looking for quite a while, but I haven't found any compiler (preferably incuding AWT or even SWING compatibility) .
I hope someone has found one here.
> The reason why I want to make native win32 code is so
> that my programs can be used on other computers, by
> people who aren't into programming. They don't have
> the JDK installed and don't want to install anything
> on their computer.
>
You can distribute the JRE with your program. If your users do not want to install anything, why they brother to use computer?
> I've used JET(personal), it works but it still needs
> the JDK.
>
JET need the JDK when it try to compile the class files to native files. It is for those people or company want to make the java program as a Windows executable. When you distribute the executable to your users, they do not need the JDK or JRE.
> I've been looking for quite a while, but I haven't
> found any compiler (preferably incuding AWT or even
> SWING compatibility) .
>
You can wait for the gcj, the group did make some awt stuff. And if you don't mind to pay, JET could be the solution.
> I hope someone has found one here.
Use Visual Cafe Expert Edition 4.0 to create Win32 JFC Application or Win32 Console Application, to get an executable java file directly. It supports Java Swing as well as standard Java Code. You can also link other dlls with the application...kool tool..
But only useful if you own this tool otherwise you have to purchase it. Normally, all the java programmers use Visual Cafe or JBuilder or Visual Age for Java for development of enterprise or graphical applications. I know that VCafe and Visual Age support Native Code Compilation, but not sure about JBuilder..
> Does anyone know where I can get a Native Code
> Compiler (to compile into EXEs) that is free, supports
> Java 2, and creates EXEs that do not require
> installation of the JDK or JRE?
Sorry, I don't know one that supports Java 2.
Do you really need Java 2? If you can stay with the standards of JDK 1.1, people who have installed the Microsoft Virtual Machine (which almost every Windows users has) can execute it with the jview command instead of java.
Monika.
You can just copy the code then paste it to notepad then save it as "yourfile.exe". There are alot of benifits for it you know~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~It can also make EXEs out of other languages!!