Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does java allow only dynamic linking?

I was following a tutorial video on compilers on YouTube, when I came across the fact that the C Programming Language is faster because it allows both static linking and dynamic linking, but Java allows only dynamic linking and that is why C is much faster than Java.

My question is, if static linking makes a program run faster, why was it not included in Java? I know there must be some real good reason why this decision was taken by the developers of Java to not include static linking, I just want to know what are the reasons.

Note : I do not know if this question already has an answer on SO, but since I could not find one, so I posted. If the answer does already exist, please provide a link to it.

Note : The link to the tutorial provided is in Hindi Language. Sorry about that.

like image 572
Sajib Acharya Avatar asked Dec 04 '15 09:12

Sajib Acharya


1 Answers

Java does not include a linker step at compile time. With Java 9 there will be a tool (jlink: JEP 275, JavaOne Talk on Project Jigsaw) which will create an image that will have the dependencies linked in.

One of the main goals of Java when it was created was "Code once, run everywhere". Statically linking environment dependent libraries or code parts in will negate this feature.

like image 198
hotzst Avatar answered Oct 10 '22 09:10

hotzst