Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I compile Java to native code?

Is there any way to compile from Java to standalone (or library) machine code without requiring a JVM?

like image 277
barroco Avatar asked Jun 07 '10 17:06

barroco


People also ask

Can you compile Java to assembly?

Yes you can. While normally Java is compiled to bytecode executed by JVM, there are compilers that output native code. For example, gcc has Java front-end, the gcj , so you can use that along with -s option (which emits assembly output instead of machine code).

Can you compile Java to binary?

Turn Your Java Application Into a BinaryThe Java byte code compiles into native code ahead-of-time (AOT). This native code runs on a Substrate VM, a minimal virtual machine separate from the Java Virtual Machine. Without (just-in-time) JIT compilation, applications can start faster with less memory.

Can Java be compiled?

Java can be considered both a compiled and an interpreted language because its source code is first compiled into a binary byte-code. This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter.

What is native build in Java?

Native Image is a technology to ahead-of-time compile Java code to a standalone executable, called a native image. This executable includes the application classes, classes from its dependencies, runtime library classes, and statically linked native code from JDK.


1 Answers

There used to be a tool called GCJ that was part of GCC, but it's been removed. Now, all the links in the GCC site re-direct to their non-GCJ equivalents.

NB: the comments all refered to my original answer saying you can compile Java to native code with GCJ.

like image 58
James Kingsbery Avatar answered Sep 25 '22 19:09

James Kingsbery