Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between packages in Java and libraries in C++ [closed]

Tags:

java

I was wondering that why in Java we have packages not libraries. I had a lot of discussion with my friends over this issue. And they were telling that we can consider packages as libraries. Since C++ already had the concept of libraries then why there was need to create a new name called Packages.

P.S.: Is it really worth to correct someone if he calls packages libraries.

like image 690
SIGSTP Avatar asked Jun 06 '13 12:06

SIGSTP


2 Answers

A package is a Java construct used to organise classes. They provide:

  • A namespace, in which to place classes
  • A level of access (package access), that allows classes in that package to share fields

That's it; what implementers do with this organizational feature is up to them.

A library is another organizational concept. However, the intention of a library is to provide a a well-defined interface to the outside world and an internal implementation to execute as needed.

Both are organizational ideas and libraries are often made up of packages (if implemented in Java). However, they have different intent and so it is sensible to give them different names. Often, a small library will fit in a single package, so using one to mean the other is probably not confusing. However, they are not the same.

like image 185
Dancrumb Avatar answered Oct 11 '22 14:10

Dancrumb


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.

like image 32
namero999 Avatar answered Oct 11 '22 12:10

namero999