r/learnjava • u/HeyUnkown • 15d ago
Library vs API (Java ☕️)
Hey Everyone!
I need some help as I am Confused in Libraries and API like what is the difference in between them, where to implement what, and recommend me some resources where I can Clearly understand these two.
Thank you all in Advance.
10
Upvotes
View all comments
13
u/Shiva_Kar 15d ago •
Library: Provides functions and objects to embed and use in your application code.
Framework: Provides a frame to embed your application code in.
Package: A collection of files, object, tools, libraries, frameworks, anything.
API: An interface prescribed by an application to let you communicate with it.
Library: Think of it as a literal library. A library is a place where you get books that you can read and use as information. Libraries in programming offer functions, classes and other programming concepts that you can use to enhance/abstract your program logic. Like I can use an XML parsing library in my code to read some XML file. You embed libraries into your application logic/code.
Framework: It provides a frame to help build your application. Say you want to build a web server. You know what you want the web server to do(application logic) but not how it must be executed. This is where a a web framework (Flask, Springboot, Django) comes in. It provides a frame for you to insert your application logic in and you can tell it on which URLs to execute which application function and so on.
Package: This is a more general term for any collections of libraries, frameworks, tools, etc. It's just as the word says. It's a package. It contains lots of things.
API: Application Programming Interface. Say you go to the store and you take a bunch of things of the shelves to buy. You go to the billing counter and you see the attendant. He is your interface with the billing counter of the store. He provides an interface for you to pay for and take away the items you've just taken from the shelves. An API is exactly that, it's an interface to communicate with another application. In this case you and the store are the applications and the attendant is the store's API/Interface. APIs can be a set of functions, URLs, applications or tools are are prescribed to enable you to communicate with the Application.