I confused with linker concept
- can we use linker in java?
- If so how linking happen in android development?
I confused with linker concept
A linker is a program that takes individual compiled files and combines them into a single executable program.
Imagine you have a program with two files: one has the main function that starts the program, the other defines a helper function. When the compiler works on the main file it will produce code that calls the helper function without actually knowing if it exists or what it does. Then the linker takes over and "resolves" the function call, so that the right function is entered when the program is run.
There are basically two types of linkers:
Usually the linker concept is applied only to native code, on the OS level. If you want to apply it to Java, you could say that it uses a dynamic linking only; the linker is integrated into the JVM.
A linker is a computer program that takes one or more object files generated by a compiler and combines them into a single executable program. Computer programs typically comprise several parts or modules; these parts/modules need not all be contained within a single object file, and in such case refer to each other by means of symbols. When a program comprises multiple object files, the linker combines these files into a unified executable program, resolving the symbols as it goes along.
Many operating system environments allow dynamic linking, that is the postponing of the resolving of some undefined symbols until a program is run. That means that the executable code still contains undefined symbols, plus a list of objects or libraries that will provide definitions for these. Loading the program will load these objects/libraries as well, and perform a final linking. Dynamic linking needs no linker.
"linker" has no significance in java world. The concept of a classloader which - given an array of java byte codes can create an internal representation of a Class this was true earlier. Now Java 9 has Linker
When Java compiler runs it produces a separate bytecode file(with *.class extension) for each class or interface in the program. This files make a symbolic connection to one another and a class file of the Java API.
At runtime, Java Virtual Machine loads program files and combines them together in a process called dynamic linking.
Unlike C/C++, linking step handled @runtime in Java ( lazily or eagerly ) via JVM. So there's no such thing like Java linker. JVM takes care of it.
In Android, prior to Lollipop, JVM was responsible to do linking. After AOT emerged ( ahead-of-time compilation ), those things started to get closer to C/C++ way. Which means, compiling and linking done prior to running the app.