【 note 】 this article translation: www.theserverside.com/tip/Library…
Libraries vs. Frameworks: The difference between these two software artifacts Libraries are low-level components that provide specific functionality, such as establishing network connections. A Framework is a known programming environment, such as Spring Boot. When software leaders start building new enterprise applications, they must decide which set of libraries and frameworks to use. This raises an obvious question: What is the difference between a software library and a framework? Both libraries and software frameworks aid in application development. The main difference between the two, however, is the scope of their tasks and the way they ease the developer’s burden of writing code. Libraries provide components, classes, and methods that developers can call to perform specific functions. By contrast, the code provided by the framework already performs the functionality normally required and calls the developer-provided code when custom functionality is needed.
Libraries and frameworks
A library is a set of related low-level components that a developer invokes to achieve a specific result. Common library functions include date formatting and establishing a network connection. Frameworks deal with higher-level problems. A framework provides an established programming environment, which itself is built on top of low-level libraries. For example, the framework might deal with how best to map all objects in an application to tables in a related database. It can also address how to provide a rich, Web-based experience to end users.
Software library Examples
An example of a library is the Java Date and Time API. It is a set of classes and interfaces that define properties and methods that developers can use to format dates, perform time zone conversions, and provide global calendar support. Java developers instantiate the Date and Time classes as needed and invoke the library’s methods in any way they see fit. Another example of a Java library is the popular Java.net network I/O package. The library consists of dozens of classes and interfaces that developers use to open network ports, process incoming connections, and send data to interconnected clients. Using only the Java.NET package, software developers can implement all the necessary logic to handle REST-based Web services or HTML-based request-response cycles over the HTTP protocol. The Java.NET library provides a set of low-level apis that any developer can use to develop applications that communicate over the network.
Popular Java libraries
Other popular Java libraries, including Spring Boot, JHipster, or Vaadin libraries that already leverage the Java framework, include:
- Apache Commons Math
- BouncyCastle for cryptography
- Java Advanced Imaging
- Java Speech
- Java 3D
- JavaMail
- Joda-Time
- Apache Collections
- Jackson for JSON and XML
- Java Networking
The role of software frameworks
Enterprise projects typically require developers to provide a set of RESTful apis for external clients to integrate with online applications. However, many developers have not only figured out how to use low-level Java.NET libraries to handle RESTful API calls, but have also shared their work as open source projects. This is the nature of software frameworks. It is an existing project that solves a common and challenging problem that developers can use in their own projects.
A framework is an existing project that solves common and challenging problems, and developers can use it in their own projects.
There are often many frameworks to choose from in a given problem domain. Within the Java ecosystem, there are a number of popular frameworks that use the standard Java and Jakarta EE libraries to address how best to handle reST-based request-response cycles, including:
- Spring Boot
- Jersey
- RESTEasy
- Restlet
- Micronaut
- Apache CFX
- JAX-RS
Frame has a point of view
Another key feature that separates the framework from the reservoir is that the latter usually includes ideas about how to solve a given problem, the scope of the problem, and how to address the framework’s goals in the most effective and efficient way. Frameworks compete on a variety of non-functional requirements, such as ease of use, performance, pluggability, and compatibility.
Frames and inversion of control
Finally, a key differentiating factor between libraries and frameworks is the relative inversion of control (IoC) between the two. IoC is often referred to as the Hollywood principle. Unlike libraries, frameworks take a “don’t call us, we’ll call you” approach to code written by developers. To develop applications using libraries, developers must instantiate library components and invoke methods of existing classes and interfaces. For example, if developers want to use java.NET libraries to create their own RESTful applications, they will need to call various apis to open ports, handle HTTP connections, format data to communicate back and forth as XML or JSON representations, And make a request when the client makes a request. The framework, on the other hand, is responsible for all the underlying plumbing needed to support the core functionality of the project. The framework calls the code provided by the developer only when needed.
The IoC and Spring the Boot
RESTful Web services written in Spring Boot embody the Hollywood principles of IoC well. With Spring Boot RESTful Web services, developers simply write the logic to execute when an HTTP-based GET call occurs. When a GET call occurs, the Spring Boot framework processes it, interprets it, converts the data exchange format to JSON or XML, and then routes the RESTful request to the developer’s business logic. The developer just writes the business logic. It is up to the framework to decide when to invoke the business logic. IoC frameworks are common in Java. Here are ten common examples.
- Hibernate
- Struts
- JavaServer Faces
- Play for Scala
- Vaadin
- JHipster
- JRuby
- JUnit
- Quarkus
- Grails
Frameworks and libraries are used together
While frameworks and libraries have different capabilities, they both help developers get more done. No software professional wants to waste time reinventing the wheel when many common programming challenges have been solved and shared in the form of licensed open source projects. Whenever you start a new software development project, it is important to choose a proven and established software development framework. At the same time, be consistent with your personal development and design philosophy. In those rare cases where a particular situation is beyond the scope of your chosen framework, the standard library is always there to help your developers bridge the gap.