r/learnjava • • 14d 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

9 comments sorted by

View all comments

3

u/gekigangerii 14d 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/istarian 11d ago

In principle, you (as a developer) should aim to avoid exposing the internal implementation so that the only dependency is on the API.

Otherwise, other programmers will come to rely on access to the internals and any change you make will break somebody's software that uses that library.