-1

In C++, a file is generated as .cpp, on compilation it becomes .obj and finally after linking, it becomes .exe. What is the final stage of a Java file? It is initially .java, on compilation it becomes .class. What is next? What happens at its final stage? Does it become an .exe file?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • Possibly (but not commonly). Usually it either stays a class or it gets packaged inside a jar. – Federico klez Culloca Sep 05 '20 at 14:23
  • "*Does it become an .exe file?*" - No. Or at lest not normally. The `.class` file is loaded by the JVM. The JVM ships with an just-in-time compiler that can compile bytecode into machine code, but this code normally does not end up on disk. [GraalVM](https://www.graalvm.org/) is capable of compiling `.jar` files (which are basicallly archives containing `.class`-files) to executables. – Turing85 Sep 05 '20 at 14:23
  • A class file is mostly the final stage, since it contains java byte code. Java byte code in class files is interpreted by the Java Virtual Machine, which also takes care of finding/resolving linkages between class files (e.g. class file A refers to class file B) in order to find Java byte code to execute. – Peter Sep 05 '20 at 14:25
  • 1
    Any beginner java book contains an answer to your question, for example [Head First Java](https://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208). There are also online resources that answer your question like the [Getting Started](https://docs.oracle.com/javase/tutorial/getStarted/index.html) trail of Oracle's Java tutorials. Did you do any research before posting your question? Please refer to [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – Abra Sep 05 '20 at 14:42

2 Answers2

0

In C++ files do not necessarily become .exe files. Such files are exclusive of Windows environments. As for Java, .class files can already be executed by the JVM so there's usually no need to convert them to anything else. Generally they stay as .class or get packaged into a variety of possible formats, such as .jar files, or .war or .ear files.

JustAnotherDeveloper
  • 2,061
  • 2
  • 10
  • 24
0

It depends on what you want to make.

Usually, after the .class file, you will have a .jar file(Sometimes it could be .war). Which you can run by using the next command. java -jar file.jar/warFile.war params

After it, you could use different programs that could create a .exe file with a .jar file and script file with a run command inside. Sometimes in .exe JRE could be inside too.