ayengin
ayengin

Reputation: 1596

Java program and JVM produced exe

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.

  1. How can I do this (create a native exe file from Java)?
  2. What will be performance of JVM produced exe vs the same C application?
  3. How Java will handle static linking and dynamic linking?

Upvotes: 2

Views: 447

Answers (4)

Peter Lawrey
Peter Lawrey

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

Stephen C
Stephen C

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

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285450

Some thoughts:

  1. You can't generate an exe using just core Java, and the JVM certainly doesn't do this. It still runs the byte code in the JVM. The actual exe that runs here is java.exe.
  2. It's hard to say if an exe would be significantly faster since the JIT generates pretty darn fast code.
  3. Java doesn't create dll's if that's what you mean, but it can interact with well-formed dll's (not .Net dll's) via JNI and JNA. If you wanted to interact with .Net libraries, I think you would need to go another route such as sockets or COM interface.

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

Andrew Thompson
Andrew Thompson

Reputation: 168845

  1. Does not make much sense to do so.
  2. Sometimes faster, sometimes slower.
  3. No idea.

Upvotes: 2

Related Questions