Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Java linker works?

I want to know how Java linker works. Specifically, in which order it combines classes, interfaces, packages, methods and etc into jvm-executable format. I have found some information here, but there is not so much information about linking order.

like image 986
Kirill Dubovikov Avatar asked Jun 22 '11 13:06

Kirill Dubovikov


People also ask

How Java works explain?

To solve this problem, the Java Virtual Machine is a simulated machine which has multiple implementations for each computers. Once Java code is compiled into JVM bytecode, the bytecode then runs according to the JVM. The JVM then passes the actual processing work to the processor in its own language.

How does Java compilation work?

In Java, programs are not compiled into executable files; they are compiled into bytecode (as discussed earlier), which the JVM (Java Virtual Machine) then executes at runtime. Java source code is compiled into bytecode when we use the javac compiler. The bytecode gets saved on the disk with the file extension .

What is linking and loading in Java?

The Java Virtual Machine dynamically loads, links and initializes classes and interfaces. Loading is the process of finding the binary representation of a class or interface type with a particular name and creating a class or interface from that binary representation.

Does Java compile to an executable?

TL;DR: Using GraalVM Java applications can be compiled into native standalone executables (will be demonstrated). Native executables of small Java programs startup blazingly fast, use considerably less resources compared to running on JVM and do not even require the JRE or any other kind of runtime apart from the OS.


1 Answers

There is no such thing as a Java "linker". There is, however, the concept of a classloader which - given an array of java byte codes from "somewhere" - can create an internal representation of a Class which can then be used with new etc.

In this scenario interfaces are just special classes. Methods and fields are available when the class has been loaded.

like image 200
Thorbjørn Ravn Andersen Avatar answered Oct 04 '22 03:10

Thorbjørn Ravn Andersen