Вопрос

Possible Duplicate:
How can I convert my Java program to an .exe file?
Compiling a java program into an exe

I believe this is an easy question, though I cannot find a quick answer.

I've been learning in a Java class about GUI making (and really Java coding in general) which, when compiled, creates a .java file. That .java file can be opened with some sort of IDE but not just opened like a .exe file.

This brings me to my question. When/where do you actually use a Java GUI? I don't foresee me passing out .java files for my friends or co-workers to use the tools I've made. Are they supposed to work best with online applications?

Это было полезно?

Решение 2

A .java file is source code which is meant for a programmer to write code in a format suitable to them, to define the behaviour of the program.

Source code is compiled into .class files which you can execute (run), although they are often packaged into JAR files (which are simply collections of .class files).

These can be executable and can be passed between people to share programs.

GUIs are irrelevant. You can either create a GUI or not, but the functionality will still exist in the code and can be executable. GUIs allow you to view and interact with a program, whereas without a GUI you have to use the command line if interaction is required.

Другие советы

Your .java file contains your Java code, which you then compile to a class file. That could be executed by your friends.

In most cases you would bundle your app with its resources in an executable jar file. If configured correctly, the operating system can run the Java app just by double clicking on it. One other solution would be to use Java webstart to distribute your GUI app but that is essentially the same thing. Java and the file association to jnlp files have to be configured correctly.

The easiest way is probably to use an exe wrapper like launch4j to create an exe file that loads the JVM and runs the Java application. Those wrappers can even create distributions with bundled jvms to make sure your application is able to run if the user doesn't have Java installed.

Hope it helps.

When Java is compiled, it creates .class files, not .java files. The .java files are source code; the .class files are the result of compilation.

.java files can be opened by an IDE, but it doesn't make sense to open them as an .exe file because, again, .java files are source code.

To run Java applications, you have to run a Java Virtual Machine which is specific to your operating system. You provide the .class file as input, and the JVM runs it.

The .class files are the Java-equivalent to Windows .exe files, in the sense that they are "executable". However, while .exe files can be directly executed by Windows, .class files aren't directly executable by any operating system but by an operating system-specific JVM.

The "strength" of Java in that respect is that the same .class file (executable) can be run on any operating system that has a JVM installed on it.

It really doesn't matter if you develop a Java GUI (graphic user interface) or a Java CL (command line) program as in the end your software is supposed to run just like an *.exe as long as the user have the "Java Virtual Machine" installed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top