Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you have Java compiled straight into machine code?

I want to do this so I have control over what platforms it's used on, and don't know C,C++ etc.

share|improve this question
up vote 33 down vote accepted

It appears that the GNU Compiler for Java can convert Java source code into either Java bytecode or machine code. It can also convert existing Java bytecode into machine code. However, the last news is from 2009, so I'm not sure how current it is and if it can handle the latest features of the Java language.

share|improve this answer
If Java bytecode hasn't changed since 2009, this should still work without developers waving "Hey! I'm still here" flags over the software. – Robert Harvey Feb 3 '12 at 0:49
@RobertHarvey I believe Java 7 introduced some new language concepts, so it might fail at converting source files into machine code. If the bytecode has also changed with these new features, then that would fail as well – Thomas Owens Feb 3 '12 at 0:58
Excelsior JET seems to be still active (commercial). There was Fujitsu TowerJ, but that seems to have died a decade ago and was pretty pointless back then. – Tom Hawtin - tackline Feb 3 '12 at 2:30
I'm using java 6 so java 7 is no problem in my case – Russell Feb 4 '12 at 5:06
Java 8 can emit new bytecodes that will break the GNU compiler, whilst Java 7 (the language) couldn't, you could get say JRuby to generate an invokedynamic, which also would have broken things.. – Martijn Verburg Nov 28 '14 at 11:13

Not quite directly answering the OP, but an perhaps an interesting aside. Java can be run in three modes:

  1. Mixed (default) - A combination of Interpreted and Machine compiled code (machine compiled == compiled by JIT at runtime)
  2. With -Xint flag - Interpreted - Byte code only
  3. With -Xcomp flag - Compiled - machine compiled
share|improve this answer
@Martjin Are this for the HotSpot? By chance do you have reference for the -Xcomp because I could not find that one in the JDK 7 documentation or the HotSpot options documentation and not sure if you have some hidden mailing list secrets that we, the mere mortals, are not aware of :-) – edalorzo Oct 30 '12 at 5:45
It is a deliberately hidden option yes :-). There are various openjdk ( mailing lists you can glean this sort of info from - or read the source code :-) – Martijn Verburg Oct 30 '12 at 15:50
Please note that according to my tests, -Xcomp can have poorer performance (by a factor of two) in some instances. – Daniel Lemire Dec 17 '14 at 18:40
Well yeah. Just in time optimizations are hard to do when the JIT isn't even running. Can have != will have. – CandiedOrange Mar 24 at 1:30

It might be better to detect the operating system using System.getProperty(“”). That would let you choose to support more than one OS, but exclude others.

share|improve this answer
Is there a way this could be fooled/gamed? – FrustratedWithFormsDesigner Feb 2 '12 at 15:18
@Frustrated, probably, but I was assuming his intent was to keep from officially supporting operating systems he hasn't tested. It doesn't make sense otherwise to intentionally disable portability you get essentially free. – Karl Bielefeldt Feb 2 '12 at 15:24
It also might be that he wants to tie the program to specific hardware in an OS-independent sort of way. – FrustratedWithFormsDesigner Feb 2 '12 at 15:28
You can force "" system property by using special arguments for JVM: java – SkyDan Sep 18 '12 at 18:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.