Is there any way to compile from Java to machine code?
+8
A:
I've never used this functionality, but gcc comes with that ability:
James Kingsbery
2010-06-07 17:45:11
+1, cool, I didn't know about that!
FrustratedWithFormsDesigner
2010-06-07 17:47:18
Yeah, gcj is the most well-known one. @isola009: Keep in mind that when compiling to native code, you will probably be working with a subset (possibly a dramatically small subset) of the *libraries* that Java normally has by default. Gnu's is pretty good, by all accounts, but well behind the current JDK.
T.J. Crowder
2010-06-07 17:51:32
It is well behind *all* JDKS starting with 1.2. I've encountered many support problems with people accidentally running GNU classpath instead of Java, and they were all without exception cured by uninstalling it and using a Sun JDK.
EJP
2010-06-08 03:09:25
Excelsior JET includes a licensed implementation of the Java SE 6 standard library and has passed the official compliance tests (JCK). It is at the 6u18 level now, the next version is expected to support 6u20.
Dmitry Leskov
2010-06-08 04:50:14
+3
A:
Yes, the JIT in the JVM does exactly that for you.
In fact it can be produce faster code than compiling the code in advance as it can generate code optimised for the specific platofrm based on how the code is rused at runtime.
Peter Lawrey
2010-06-07 19:01:55
Yes, you are correct that the JIT does it and does it very well. It does not make a stand-alone executable, but then the OP wasn't asking about that....
Bill K
2010-06-07 21:19:42
Just in case, there are free licenses for non-commercial projects.
Dmitry Leskov
2010-06-08 04:57:40