How to run java program without JVM?

I have a simple java program that will just print Hello World.Can is it possible to print without using the JVM installed on the machine? But the compiler is there.

+3


source to share


5 answers


You can compile Java bytecode to machine code using something like this: http://en.wikipedia.org/wiki/GNU_Compiler_for_Java

Or you can use any of the MANY Java to C / C ++ converters to create a C / C ++ version and compile that. (Google search for "Java C Converter")



Warning: I have never tried any of these, including the linked GNU compiler, so I cannot make any attestations regarding their usefulness or quality.

+9


source


@SplinterReality already pointed you to some compilers (the Java Bytecode to Native Compiler link will show you a few more options).

I'll just tell you that some people are a little confused:

JVM is a program that takes java bytecode you get by running javac in java source(or you create it in some other way). Bytecode is just a set of instructions that the JVM understands, so it gives you a sequential set of opcodes that are platform independent. It is up to the JVM to then map these opcodes to native instructions, so JVMs are platform dependent. So when you compile your java source code to java bytecode, you can run it on every platform.



This is why, if you have a java source or bytecode, you can take it and just compile directly to native code (platform dependent, in fact sometimes exactly what the JVM, or rather the JIT, does is compile to native code when he sees the need). Even more for the JVM than just interpreting bytecode - for example, you need to take care of garbage collection.

So the answer is yes, but do you really want to do this? Unless you want to run it on some embedded systems, I really don't see a reason.

+3


source


Compiler -> just compiles the code. checks for possible flaws and converts the code to byte code.

JVM -> Actually execute / run (interpret) bytecode generated by the compiler.

So, the answer is no .

0


source


If this program is the source code of one file (not compiled in bytecode), you can;) Here or here . It will be good here;)

Just put it on and click compile and run

.

But it will only work with simple stuff and you should have the source code.

I would not be surprised if there was a site that would allow loading the class from PC users

0


source


It's like I can drive a car without an engine or wheels. You can not. JVM is what java does.

-1


source







All Articles