Reputation: 1596
Java is platform independent , because it use a platform dependent JVM to launch a Java program. JVM understands bytes codes and executes program. I know old way of doing this was interpreter. But now JVM's is using JIT. But I didn't understand JIT concept clearly. I think, a jVM can translate byte codes to an exe (for Windows) and after this I can run this translated program without JVM. But I can see generated exe in .net JIT but I cannot see generated exe in Java.
Upvotes: 2
Views: 447
Reputation: 533880
How can I do this (create a native exe file from Java)?
There is a common mis conception that this will be better in some way. However, I haven't seen a good situation where it is. There are products like Excelsior JET which can compile a binary. GCC can compile a binary for Java 1.4 but this is not a current project AFAIK.
What will be performance of JVM produced exe vs the same C application?
You can't compare the two. If you want an Object Orientated Program, you can't easily write this in C and it will almost certainly be much slower to write if not run. If you want to write a C style program, write it in C.
How Java will handle static linking and dynamic linking?
The JVM does dynamic late linking. If fact it can link and re-link code multiple times as you load and unload class loaders.
Upvotes: 0
Reputation: 719679
I think, a jVM can translate byte codes to an exe (for Windows) and after this I can run this translated program without JVM.
This is not correct.
In reality the Hotspot JIT compilers work by compiling individual methods to native code within the running JRE. They typically only bother to compile methods after they have been called a few times to gather stats on typical execution paths. No "exe" is ever produced by the Hotspot JIT compilers.
1) How can I do this (create a native exe file from Java)?
There are third party applications that will do this. However, by doing this you lose a lot of the advantages of JIT compilation, such as optimizing for the execution patterns of the current program run.
2) What will be performance of JVM produced exe vs the same C application?
That depends on the application.
3) How Java will handle static linking and dynamic linking?
Java doesn't handle this. It depends on the 3rd party application that you use to create the executable.
I would recommend not going down this path. If it is critical that you distribute your code as ".exe" files, you probably shouldn't be using Java.
Upvotes: 1
Reputation: 285450
Some thoughts:
Also as an aside, there do exists programs that create exe's from java classes, but most create files that still require a JVM, and the good ones that don't I believe are not free.
Upvotes: 4
Reputation: 168845
Upvotes: 2