Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java packages vs. C++ libraries

Tags:

java

c++

package

In Java, there is what is called package. Does library in C++ represent the same meaning, especially in terms for example of containg relative classes and the use of protected members?

Thanks.

like image 863
Simplicity Avatar asked Jan 25 '11 11:01

Simplicity


People also ask

What is the difference between libraries and packages in Java?

Packages are namespaces. There are uncountable "Util" classes, but you can uniquely identify them because of their fully qualified name that is the package + class name. A library is a set of classes that concur to provide a feature/functionality. Maybe you mean unlimited but not uncountable.

What is the difference between a package and a library?

However, it is often assumed that while a package is a collection of modules, a library is a collection of packages.

Does Java have libraries or packages?

Java comes with a core set of libraries, including those that define commonly used data types and related behavior, like String or Date; utilities to interact with the host operating system, such as System or File; and useful subsystems to manage security, deal with network communications, and create or parse XML.

Does C# have packages like Java?

As an alternative of Packages in Java, the C# language has namespace.


1 Answers

There are different dimensions of what a package means in Java. As a container that differentiates the names of the classes inside from the names of classes in other packages, its equivalent would be c++ namespaces.

As a unit that guarantees access to non-private members to classes in the same block, there is no equivalent in C++. The access level granted to a class is independent of the namespace where the class is defined.

As a way of ordering your sources in the disk, there is no equivalent, the C++ language has no requirements on how the code is stored in files.

Regarding c++ libraries, that is closer to jar files in Java. They bundle different classes that share some relation. A jar can contain more than one package, and more than one jar can contain classes from the same package. Similarly with libraries, they can contain classes from different namespaces and/or different libraries can contain classes from the same namespace.

like image 181
David Rodríguez - dribeas Avatar answered Sep 28 '22 03:09

David Rodríguez - dribeas