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
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
Java contains many libraries in those packages (Swing, etc.), and the API is the interface by which we request services (perform actions, etc.).
API is a logical representation of non-empty collection of Java classes and interfaces (add annotations and enums).
Library (being JAR Java library) is a unit of deployment of one, many or part of 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.
Excellent resource that covers these relationships is Robert Martin Principles of OOD - look for last 6 package principles.
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.
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.
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.