Celeritas
Celeritas

Reputation: 15063

What's the difference between classes and libraries in programing languages?

For example in C++ I thought anything #included was a library, but then I see I am wrong for example ifstream is refereed to here as a class. On MSDN they don't use the word class or library.

If a library may offer classes or functions, then how is it different than a package (in the Java sense)?

Upvotes: 0

Views: 121

Answers (3)

JBL
JBL

Reputation: 12907

To be perfectly language-agnostic, a library would be conceptually a collection of features. Period. It may offer functions, it may offer classes to create instance of (in languages that have classes, some don't have that concept).

A class is an Object Oriented Programmation concept which describes an entity which has (possibly) data and (possibly) behaviors (or functions/methods), with notions of encapsulation through the use of public/private access to data and/or functions.

As you tagged C++ and Java, I'll answer a bit more precisely regarding these languages. Both have classes (Java has more than classes, it works only through classes). You can find libraries for these languages that can offer a set of classes and functions (in Java, that could be done for example with static functions accessible without any instance of the class it belongs to).

Now about your example:

In C++, you include headers. They can come from libraries. You mentioned ifstream which is a class part of the C++ standard library, accessible through a header of this standard library.

Upvotes: 2

Helios
Helios

Reputation: 851

In general we consider that a library means a collection of classes which helps to develop software. But it is not true for every language existing in this world. A library may contain a certain number of classes but it's not mandatory to have that, it may contain subroutine or type def or anything of that sort.

Where a class provides a specific functionality or few specific ones.

Now it depends on the language how they set the structure of their library or user accessibility to it.

Upvotes: 0

sotondolphin
sotondolphin

Reputation: 223

The library is a compilation of different classes(in c++/c#, classes are packed in .dll format. in java classes are packed in .jar format). Some libraries contain classes that provides services for specific functions. Whereas some libraries contain classes for all-sorts of tasks.

A class is an implementation of a certain behavior using a programming language in the object oriented way.

Upvotes: 0

Related Questions