开发者

Java and windows? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicates:

Compiling a java program into an exe

How can I convert my java program to an .exe file ?

hi everyone . there are many programs such intellij idea or jedit which they have written in JA开发者_开发技巧VA , How they have compiled the code into the exe file ? How can ,I compile my java code to exe file and run it on windows? And Why javac give us class file ? what is it ?


how about searching stack overflow:

How do I create an .exe for a Java program?

also, like the answer points out launch4j is the program you want to use. i have used it and it works well.


mkoryak took care of how to create an .exe for a Java program, but let me address "What is a Class file"?

In general, you don't have to compile Java down to byte code in the form of an exe (or anything else). You compile .java files into .class files. These files can't be run by an OS directly - rather, they are run by the Java Virtual Machine (JVM). The JVM is essentially a layer between your Java program and the underlying OS. The JVM will, on your behalf, interpret your .class files and pass the instructions contained in them to the underlying OS (Windows, OS X, Linux, etc).

So what does this do for you?

For one, it makes Java a little slower than other languages that are compiled right down to byte code. This was initially a big knock against Java but, as JVM interpreters have gotten better and people have migrated to slower platforms (i.e. Web Apps), this minor latency issue has become less and less of a problem.

On the flip side, however, you can write your Java code for a single OS - the JVM. You don't need to write one version of your app that targets Windows and another that targets OS X, and another, and another... Rather, you write one version of your application and you target that single OS (the JVM). The fact that there are versions of the JVM for every major OS out there means that, as soon as you write a Java program, you can run it on any platform (in theory, anyway).

That's one of the really cool things about Java, and also the meaning behind the often-heard tagline: "Write once, run anywhere."

So that's what the .class files are all about.

In Java, you write .java files and use a Java compiler (such as javac) to create .class files. These .class files are then run by a Java runtime (such as java), which executes your program on the JVM.

I hope that helps and, maybe, you don't need to compile your Java program down to an exe, at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜