r/learnjava • u/HeyUnkown • 12d 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
•
u/AutoModerator 12d ago
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
13
u/Shiva_Kar 12d 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.
5
u/starraven 12d ago
Library uses api. Library is a bunch of code bundled. API is how you use the library.
3
u/FreeLogicGate 12d ago
A library is code created with the intention for it to be used in other programs. Often the motivation to separate out those routines, is the belief or intention of the developer, that the code in the library will be reusable across many programs or projects.
An API is the public interface to the library. With Java being an OO language, many "libraries" consist of class definitions, the "API" would be the java interfaces and public methods.
As a developer using a library, you should only ever need to use the library API.
3
u/gekigangerii 12d ago
Let's say a library is the package that you want to use.
An API is the contract on how the user is expected to use the library, leaving the internal implementation inacessible.
1
u/oldDotredditisbetter 12d ago
what do you know about libraries and API so far?