Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is the difference between a library, framework, and API? They all seem the same to me. I would like to hear peoples thought of this.

share|improve this question

closed as not constructive by gnat, Kilian Foth, Martijn Pieters, Glenn Nelson, thorsten müller Feb 25 '13 at 12:52

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

4  
3  
4  
2  
@Jorg: You should've submitted this as an answer. As it stands that is borderline spam and clogs up the page. –  Sergio Mar 4 '11 at 1:55
2  
@Sergio - Jörg W Mittag has 1171 thoughtful and well-received answers on SO (42 thoughtful and well-received answers here). He's not trying to be difficult. He's trying to improve P.SE by showing how unnecessary this question is (not to mention that no answer here mentions the distinguishing characteristic of a framework yet). –  Corbin March Mar 4 '11 at 3:36

8 Answers 8

up vote 32 down vote accepted

A library is a collection of functions / objects that serves one particular purpose. you could use a library in a variety of projects.

A framework is a collection of patterns and libraries to help with building an application.

An API is an interface for other programs to interact with your program without having direct access.

To put it another way, think of a library as an add-on / piece of an application , a framework as the skeleton of the application, and an API as an outward-facing part of said app.

share|improve this answer
6  
That's not a very good definition of a framework. I wouldn't really call any framework a "collection of patterns and libraries" –  TheLQ Mar 3 '11 at 22:22
    
A framework is more like an environment to build in. Other than that +1 –  Klaim Mar 3 '11 at 22:24
    
yeah, I was at a bit of loss for words on that one. anyone have any better suggestions? other wise feel free to edit. I went looking on wikipedia, which calls a framework: "Frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined Application programming interface (API)", which seems to cause more confusion in the context of this question than help. –  GSto Mar 3 '11 at 22:50
3  
A library is when your code is in charge (your code "uses the library") and a framework is when it is charge (the framework "runs your code"). For instance, a framework dictates a what order things must happen (Swing, servlets) whereas with a library you decides when and how it gets used (image conversion, encryption). An API is just a definition of a bunch of function you can call, and is a part of both libraries and frameworks. –  Martin Wickman Apr 29 '11 at 22:15

Good answers so far but they miss one key point - a framework uses IoC. Your code is surrounded by a framework. It lives inside it. In contrast, your code just uses a library or API. It lives outside it. IoC is the difference.

share|improve this answer
    
Not necessarily true. A framework can use IoC, and your application can live inside a framework, but it does not have to. Stupidly the Wikipedia entry on Frameworks lists this as a 'distinguishing feature' of a framework, and references this dissertation "dirkriehle.com/computer-science/research/dissertation/…;, but the dissertation itself doesn't contain the phrases 'inversion' or 'ioc', and actually states "Typically, applications use not only one framework, but several." (p26, ref p9) –  Kirk Broadhurst Mar 4 '11 at 5:56
11  
@Kirk Broadhurst-was actually thinking of Martin Fowler:"Inversion of Control is a key part of what makes a framework different to a library(...)A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code..." If we conclude IoC isn't a distinguishing feature, then there is no distinguishing feature - they're all the same and that's no fun. –  Scant Roger Mar 4 '11 at 6:13

A library is a collection of code built to perform common tasks. Library code tends to be relatively stable and bug free. Use of appropriate libraries can reduce the amount of code the need to be written. It will tend to reduce line of code counts for an application will increasing the rate at which functionality is delivered. In most cases, it is better to use a library routine than to write your own code.

An API (Application Programming Interface) is interface to some functionality which allows an application to access the available functionality. An API may be referred to as an Interface. API exist at many levels including system, library, framework, program, and application. APIs should be defined before the code implementing them is implemented.

APIs should be stable, although portions of the API can be deprecated for various reasons. The more broadly used the API the more difficult it is to change it. Most if not all of the Java 1.0 API is still available, although many methods are have been deprecated.

A Framework is a collection of APIs designed to make building of applications simpler. Frameworks provide implementations for reusable components. Good frameworks tend to be specialized in their application.

The Java Collections Framework is a collection of APIs to various types of objects that can be used to handle collections. It provides a hierarchy of APIs to various collections. The in the Java Collections Framework the SortedSet interface extends Set interface which in turn extends the Collection interface. These APIs are abstract interfaces, and the actual implementations have different names. The Collections Framework makes implementing collections simple, and simplifies changing implementations during development.

Frameworks can be built of smaller frameworks as is seen in the Java Spring Framework targeted at J2EE development. Spring consists of over a dozen frameworks, many of which can be used on their own or replaced by other frameworks.

Use of the appropriate libraries, APIs, and frameworks can simplify development. These components take care of the common issues, and allow the development team to focus on the application specific issues.

share|improve this answer

A framework is a step up from library. If your toolbox is a library then your workshop would be a framework.

Wikipedia says

An API is an abstraction that describes an interface for the interaction with a set of functions used by components of a software system

The important distinction between an API and a user interface is that an API lets other software/services interact with your solution programatically.

API's can be built both for applications (through dll's or plugins) or websites and services (through REST and webservices)

share|improve this answer
    
Nice analogy... –  sunwukung Mar 4 '11 at 9:06

APIs define how to use something else in terms of what objects and methods can be used from a source. For example, integrating Twitter or Facebook into a site uses an API from Twitter or Facebook to ensure the proper data is updated.

Frameworks tend to be a bit bulkier in a sense as this can almost form its own language at times. jQuery being an example of a framework which has its own syntax and carries a bit more weight in terms of getting into my code in a sense. Frameworks can also be platforms that make them similar to APIs in a sense,e.g. the Win32API or .Net Framework each have numerous methods for building an application so there can be Frameworks that have APIs in them and APIs that are also viewed as Frameworks.

Libraries tend to be binary files that implement an API or Framework and so they are the bits that you have to have to use an API or Framework in some cases. At least that is how I see these terms and the differences among them.

share|improve this answer

Go to a library and start reading books. If you are the application then the collection of books is the library. The shelves, the cupboards, and the compound that houses all this constitutes the framework. Everything you come in contact while performing the task of reading the books is the API.

share|improve this answer
    
This is a wonderful answer. –  Magus Feb 27 at 0:19

A library is a collection of code that is used to simplify common tasks - it can be classes, functions or whatever is specific to your language or platform. A good example might be a string manipulation library that provides helpers for common tasks (building, splitting, searching or sorting strings etc).

An API (application programming interface) is a definition ('interface') of how to work with another application, system or technology. It essentially defines the operations that are available to interact with that other system. An API can be a library (meaning that the API is wrapped in a library or set of classes), but the distinction is that an API always references an external system - whether it's a database, web service, another application, or the operating system itself.

A Framework is a larger concept - it will normally contain a number of libraries and APIs to perform common tasks. It exists on a higher conceptual level - it's not just a collection of tools, but also a collection of design patterns, best practices, and methodologies. A software Framework is an extension of a a general framework - its meanings include being a foundation from which things are built, providing support and structure, and giving guidance and definition to requirements.

share|improve this answer

The application is developed using libraries based upon a framework and communicates through a API.

If you building a app say a online image processing application,

  • You can use some pre written image processing libraries.
  • on any framework you know which will guide you to construct the application.
  • You will be providing the application some way to interact with outside world..that would be your applications API to rest of the world.

When a call comes in to your application

  • it would be handled in a way how you designed with guidance of framework
  • processing the call carried by library
  • these functions will be accessed through the your API from outside world

to the calling person

reasons why these exist:

  • library : saves you from reinventing the wheel
  • framework : saves you from unexpected traps of system design and handling unless the framework itself has flaw's
  • API : ensures the security of application by interfacing the core from the real world access
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.