Compile a java program into real machine code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myusernotyours
    New Member
    • Nov 2007
    • 188

    #1

    Compile a java program into real machine code.

    hi all, I'd like to know whether it's possible to compile a java program into actual machine code so that the program runs without the need for the Java Runtime.
    If it's possible how can it be done?

    Thanks in advance.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by myusernotyours
    hi all, I'd like to know whether it's possible to compile a java program into actual machine code so that the program runs without the need for the Java Runtime.
    If it's possible how can it be done?

    Thanks in advance.
    Your Java bytecode *is* compiled to real machine code but you need the virtual
    machine (JVM) for it. It's the JIT (Just In Time) compiler that does the job. It is
    fired up by the HotSpot mechanism that checks if a piece of code is executed
    more than once; if so, the byte code is transformed to the machine code of the
    native platform.

    There is no need to attempt to transform the byte code of the entire JRE (all the
    core classes etc.) to machine code; the resulting executable file will be huge
    which you don't want.

    kind regards,

    Jos

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Originally posted by myusernotyours
      hi all, I'd like to know whether it's possible to compile a java program into actual machine code so that the program runs without the need for the Java Runtime.
      If it's possible how can it be done?

      Thanks in advance.
      Hi!
      If what you're attempting is, to have an executable which will run on a system without the JRE, there are possibilities. However, your program will loose platform-independence and might become slower.

      For Windows systems for example, just search the web for "jar to exe" or similar. Then all you'll have to do is create a jar-file of your program and use the software found by that search to create an executable file from it.

      Depending on your code, a cross-compiler might be another solution - if you have it translated for example to C++ (or C for that matter), you could compile it to an executable directly. However this will not work in all cases and you'd possibly be better of with either using the above method or rewriting your program in a different language (that is, if you really want to do without the JRE).

      Greetings,
      Nepomuk

      Comment

      Working...