While working with JAVA when compiler compiles are .java classes. It produces .class files and after compilation, the linker links all .class files to create one single file. My question is that what use to be the extension of that single file produced by the linker in the case of JAVA Langauge?
-
It does not. Java is not compiled in that way. There is no linker. There is a class loader at runtime. https://en.m.wikipedia.org/wiki/Java_Classloader – Boris the Spider Dec 18 '21 at 11:36
-
@BoristheSpider does the class loader work the same as loader ? is it not then how classes and predefined java libraries are linked in JAVA ? as they are done through linker in C++. – Umair Dec 18 '21 at 11:42
-
1Java is not C++! The JVM is written in C++, the JVM executes Java _bytecode_. – Boris the Spider Dec 18 '21 at 11:43
-
yes @BoristheSpider I am getting your point but my question is that once the code is compiled and .class files are created. Now how will java links these classes and libraries? – Umair Dec 18 '21 at 11:46
-
1There’s a single word answer to that - **dynamically**. – Boris the Spider Dec 18 '21 at 12:39
2 Answers
The class file format as produced by the java compiler is exactly the same as expected by methods like ClassLoader.defineClass
at runtime. There is no linking operation in-between that would alter these files or convert them to a different format. The actual linking happens at runtime in the JVM after the classes have been handed over.
For two decades, Java programs were mainly deployed using jar files. Jar files are zip archives with certain predefined entries containing meta information. Besides that, jar files contain class files and resource files in the same format as used in ordinary directories of the default filesystem. This is the reason why you can name jar files and directories in the classpath and it makes no difference to the class loading process.
Alternative deployment approaches were developed but they all boil down to reproduce the bunch of class files in the target environment, to be able to load them.
Runtime environments may have implementation specific files containing pre-linked data for speeding up the startup process, like the jsa file used by HotSpot’s Class Data Sharing but these files are specific to a particular installation and not to be deployed to another machine.
With the introduction of the module system, new file formats were introduced. Modular JAR files and JMOD. They are closer to what you might have in mind when thinking about a linker output, as they are supposed to hold a single module, in other words, only related classes. However, they are still just containing class files.
There’s the option to create a pre-linked module image file using jlink
to be bundled with a JDK. So unlike the jsa files, these images are deployable to different machines with compatible architecture, but tied to the JDK they’re bundled with and hence, still implementation specific.
So there’s no documented, implementation independent format for pre-linked Java software. The common denominator still is a collection of class files.

- 285,553
- 42
- 434
- 765
Class files are "linked" when the class is first used in the JVM. It's done in memory, so there is no file.
In GraalVM it's probably the same .exe/.dll/ELF executable as for traditional C compilation.

- 792
- 1
- 18