Last Updated:

What is the difference between a framework and a library?

In this article, we will talk about what a framework is and what is a library, find out what is the difference between them? We will also consider their connection and ways of communication in the program.

Framework or library? These two completely different tools sometimes confuse novice Java developers, so let's start with a simple diagram.

Video version of the article:

The Difference Between a Library and a Framework

The main difference between the library and the framework is the control inversion. When working with a library (for example, calling a method), you control the process of what and when to call. In addition, the library is essentially a code base and is used as part of the program without affecting the architecture of the application.

When using the framework, control inversion occurs: the framework controls when to call a particular user method. In fact, the framework defines the architecture of the developed application, extending it with the functionality described by the programmer. Even the very name "framework - from the English framework (framework)" speaks of its purpose to be the basis, base, architecture of the application. At a basic level, the interaction of the library and the framework in the program is as follows:

Framework

As we already know, a library is a set of classes and is designed to reuse code that has already been written by other developers. Library classes and methods typically define specific operations that are available for use by other applications.

In the framework, most often the control and behavior of the program is already predetermined, and the developer only needs to expand the functionality without worrying about the architecture of the application. Instead, the framework is doing it.

Interaction of the library and the framework

  • Each of these components defines an API with which a programmer can integrate them into his application.
  • The framework provides an interaction interface, and the library provides functionality.
  • A typical development process typically begins with defining a framework and interaction mechanisms, and then populated with user-defined functions and functions defined in API-connected libraries.

Stay tuned for new articles on Java and Android!