Omkar Salokhe
Omkar Salokhe

Reputation: 73

Are there any commands to get the intermediate files of Compilation for Java Code?

Similar to C or C++ where you can get the intermediate files are there any commands to get same for Java Code?

For example, C file can generate,

Preprocessed File (Hello.i)
Compilation file (Hello.s)
Assembly File (Hello.o)
Executable File through Linker (Hello.exe)

In java we do,

Executing --> Filename.java
we obtain --> Filename.class

and then we run this class file for output.

Is there a way to generate Preprocessed, compiled and assembly files for Java code?

Upvotes: 0

Views: 502

Answers (2)

Mark Jeronimus
Mark Jeronimus

Reputation: 9543

The .class file is already an 'intermediate' file. The Java Virtual Machine then takes this and executes it (interpreting or compiling as it sees fit, often both!)

If the class file is not obfuscated, you can easily disassemble the contents with a decompiler, as all/most symbols are preserved ( like debug symbols in C/C++). Some IDEs allow you to open a .class file and see the disassembled code (IntelliJ and NetBeans come to mind)

IntelliJ shows the decompiled code as if you're looking at a regular .java file, although with no comments and sometimes 1-letter variables. You can view the bytecode (disassembly) using a menu option (even of your own source code as long as it's compiled).

NetBeans shows it, afaik, only as byte code, but still grouped by method.

Upvotes: 1

Kayaman
Kayaman

Reputation: 73548

No. The Java compiler generates bytecode (contained in .class), there are no intermediary steps.

The JIT compiler(s) then generate assembly and machine code, and those can be seen with suitable flags given while running the program.

Upvotes: 2

Related Questions