Java API 和库之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1322809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between a Java API and a library?
提问by
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
? I can connect to a class like System
without using any API here, so why we say as J2SE API rather than J2SE packages?
我知道一个 API 被称为一组用于调用某些东西的函数,一个库是一个类的集合,但是包中的 API 到底是什么java.lang
?我可以像System
在这里不使用任何 API一样连接到一个类,那么为什么我们说是 J2SE API 而不是 J2SE 包呢?
采纳答案by geowa4
Straight from Wikipedia:
直接来自维基百科:
In computer science, an application programming interface (API) is an interface that defines the ways by which an application program may request services from libraries
在计算机科学中,应用程序编程接口 (API) 是定义应用程序可以从图书馆请求服务的方式的接口
Java contains many libraries in those packages (Swing, etc.), and the APIis the interface by which we request services (perform actions, etc.).
Java 在这些包中包含许多库(Swing 等),API是我们请求服务(执行操作等)的接口。
回答by Jesper
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.
API(应用程序编程接口)是库的外观,用于使用它的程序。它是其他程序库的“面孔”。库的 API 是库中可公开访问的类、接口和方法的集合。
You wrote:
你写了:
I can connect to a class like System without using any API here...
我可以在不使用任何 API 的情况下连接到像 System 这样的类...
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 areusing the API of the standard Java library if you are using class System.
事实并非如此 - System 类是 Java 标准库中的公共类,因此它是标准 Java 库 API 的一部分。您正在使用标准的Java库的API,如果你使用的是类系统。
Why do you think you "are not using any API" when you use class System?
当您使用 System 类时,为什么您认为您“没有使用任何 API”?
回答by Bill K
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).
API 是您访问库(或任何一组类)的方式。
回答by Andreas Dolk
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.
一个简单的经验法则刚开始:库是 Java 类的集合,通常但不一定位于 jar 文件中,并且这些类的所有公共方法构成该库的 API。
(the cleaner the code, the more you can rely on this rule ;) )
(代码越干净,你就越能依赖这个规则;))
回答by topchef
API is a logical representationof non-empty collection of Java classes and interfaces (add annotations and enums).
API 是Java 类和接口(添加注释和枚举)的非空集合的逻辑表示。
Library (being JAR Java library) is a unit of deploymentof one, many or part of API.
库(即 JAR Java 库)是一个、多个或部分 API的部署单元。
There is no one-to-one or many-to-one association between two in general since their concerns are orthogonal in nature: API is concerned with logic and functionality; library is concerned with deployment.
两者之间通常没有一对一或多对一的关联,因为它们的关注点本质上是正交的:API 关注逻辑和功能;库与部署有关。
Excellent resource that covers these relationships is Robert Martin Principles of OOD- look for last 6 package principles.
涵盖这些关系的优秀资源是OOD 的 Robert Martin 原则- 查找最后 6 个包原则。
回答by prasad
package contians limited number of classes and interfaces, where as an API contains "MORE" classes and interfaces.but it is not a java interface.
包包含有限数量的类和接口,其中 API 包含“更多”类和接口。但它不是 java 接口。
回答by prasad
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
api 是开发所需的类集,库是 api 的一部分,例如,假设您需要通信 api 但您只需要串行通信,因此串行通信类集是库,通信类集是 api
回答by Venkataswamy
API, Library, and Framework are related-so-confusing terms.
API、库和框架是相关的令人困惑的术语。
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.
API:库的抽象,提供库的抽象视图,它会建议库中的内容以及我们如何访问它们以使用它们。它还可以提供关于库中实现的组件的功能和关系的分类和描述。
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.
资料来源:我阅读一些书籍和网络资源后的理解。
回答by oshan
Api is a list of all classes that are part of the JDK .it all includes all Java Packages,classes and interface ,along with their method,field, and constructor.
Api 是 JDK 中所有类的列表。它包括所有 Java 包、类和接口,以及它们的方法、字段和构造函数。
A java package is a technique for organizing java classes into namespace similar to the modules of Modular,provide modular programming in java packages can be in compresses files called JAR files,allowing classes to be downloaded fast as groups rather than individually.
java包是一种将java类组织到类似于Modular模块的命名空间中的技术,提供java包中的模块化编程可以在称为JAR文件的压缩文件中,允许类作为组而不是单独下载。
回答by Kowsigan Atsayam
In object-oriented programming , a class library is a collection of prewritten class es or coded templates, any of which can be specified and used by a programmer when developing an application program. 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.
在面向对象编程中,类库是预先编写好的类或编码模板的集合,其中任何一个都可以由程序员在开发应用程序时指定和使用。您可以在各种项目中使用库。框架是帮助构建应用程序的模式和库的集合。API 是其他程序与您的程序进行交互而无需直接访问的接口。