-1

I confused with linker concept

  1. can we use linker in java?
  2. If so how linking happen in android development?
Round Robin
  • 77
  • 3
  • 11
  • A linker is an application that takes compiled object files (emitted by a compiler) and uses them to build executables 'linked' to their necessary libraries. The closest thing to linking in Java would be a [classloader](http://stackoverflow.com/questions/2424604/what-is-a-java-classloader)... Not sure where you want to go from there, but in android development it works the same way. – PinnyM Oct 07 '13 at 12:03
  • @pinny-->does this classloader responsible for executable file? – Round Robin Oct 07 '13 at 12:05
  • 1
    In Java, you don't wind up with an executable file in the standard sense. Just a bunch of bytecode compiled objects ('jars') of which at least one will provide an entry point that the JVM can call into. As such, the primary function of a linker isn't really needed. The classloader assists the JVM at runtime in pulling together the necessary objects for execution. – PinnyM Oct 07 '13 at 12:07
  • @PinnyM-->thanks for ur effort. – Round Robin Oct 07 '13 at 12:13
  • This question is a bit confusing and non-descriptive. Linker is a Compiler phase system which is doing something beneath the "Java Development" per se. What you actually mean in "using linker in Java"? Java compiler uses linker but I'm not sure that developer should be worrying about this. This may further confuser the learners or newcomers to Java. – Giorgi Tsiklauri Dec 11 '18 at 16:24

4 Answers4

5

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:

  • a static linker runs before execution, generates as output a fully linked executable file that can be loaded and run.
  • a dynamic linker is run when an executable file is executed, looking up needed symbols in different libraries.

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.

ecm
  • 2,583
  • 4
  • 21
  • 29
Joni
  • 108,737
  • 14
  • 143
  • 193
1

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

Community
  • 1
  • 1
Trying
  • 14,004
  • 9
  • 70
  • 110
0

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.

Sayat Satybald
  • 6,300
  • 5
  • 35
  • 52
0

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.

stdout
  • 2,471
  • 2
  • 31
  • 40