Java: Static Linking


When it comes to software development, it is a good thing to be a lazy programmer. If a programmer reuses code that he, or someone else, has already written, he can spend more time working on code for new functions. Developers can incorporate existing code libraries with either static or dynamic linking. Java uses dynamic linking by default, but programmers can statically link their own files.

Software Libraries

  • The software libraries on which programs depend can either be for major systems, such as 3D graphics software, or contain code that performs functions specific to particular categories of software. The way in which a library's files are linked to the program's files will depend on how common the library is, and the installation processes for individual operating systems. Linking can be static, in which a program's executable includes all the library code it needs, or dynamic, in which the program looks for library files on the machine executing it.

Dynamic Linking

  • All linking is done by a programming language's compiler. When a program is dynamically linked, the compiler tells the application where to find necessary library files in particular operating systems. If the library file is not where the compiler told the program to look, the application will not be able to run properly. Dynamic linking requires that library files follow a uniform process when they install on user machines, with the files ending up within a specific directory path. Without this predictability, programmers cannot tell dynamically linked programs where to find library files.

Static Linking

  • When a program is statically linked, the compiler puts the binary code for every library file on which an application draws in the executable it produces. This process will produce a larger executable file than a dynamically linked program, but ensures that a program will run correctly on the end user's machine. Programmers usually use this technique for software libraries that are uncommon and unlikely to be installed on the average computer.

JVM Linking

  • Java executes its bytecode with the JVM, which includes all the files in Java's standard library. Because of this, the Java compiler will automatically use dynamic linking for any standard library file. However, sometimes Java programmers rely on older or customized versions of standard library files. If a programmer includes the text "MyLibrary extends StandardLibrary" at the top of a library file, where "MyLibrary" is the title she wants to use for her library file and "StandardLibrary" is the library file she wants to replace, the compiler will statically link the developer's version of the library file to the Java application.

Related Searches


Promoted By Zergnet


Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!