What is the difference between a Java API and a library?

前端 未结 10 1537
面向向阳花
面向向阳花 2021-01-31 21:10

I know that an API is called a set of functions used to call something, and a library is a collection of classes, but what is actually API in package like java.lang

相关标签:
10条回答
  • 2021-01-31 21:39

    The API (Application Programming Interface) is what a library looks like from the outside for a program that's using it. It's the "face" of a library to other programs. The API of a library is the set of publicly accessible classes, interfaces and methods in the library.

    You wrote:

    I can connect to a class like System without using any API here...

    That's not true - class System is a public class in Java's standard library, so it's part of the API of the standard Java library. You are using the API of the standard Java library if you are using class System.

    Why do you think you "are not using any API" when you use class System?

    0 讨论(0)
  • 2021-01-31 21:44

    API, Library, and Framework are related-so-confusing terms.

    API: Abstraction of Library, offers abstract view of a library which will suggest what are in the library and how can we access them to make use of. It may also provide the classification and description about the functionality and relationship of the components implemented in the library.

    Library: Set of actually implemented and ready to use components

    Framework: It may be a part of library or some times may use more than one library to offer a particular category of services.

    Source: My understanding after reading some books and net sources.

    0 讨论(0)
  • 2021-01-31 21:45

    Just to restate what I think others are saying more briefly:

    A library is a set classes that are generally organized and packaged in some coherent manner to promote reuse.

    An API is the way you access a library (or any set of classes).

    0 讨论(0)
  • 2021-01-31 21:46

    A quick rule of thumb just to start with: a library is a collection of java classes, usually but not necessarily located in a jar file, and all public methods of those classes form the API of that library.

    (the cleaner the code, the more you can rely on this rule ;) )

    0 讨论(0)
  • 2021-01-31 21:47

    package contians limited number of classes and interfaces, where as an API contains "MORE" classes and interfaces.but it is not a java interface.

    0 讨论(0)
  • 2021-01-31 21:50

    api is the set of classes that require for the development and library is part of api for ex.suppose you need the communication api but you need only serial communication so the set of serial communication classes is library and the set of communication classes is api

    0 讨论(0)
提交回复
热议问题