- Namespace
-
This article is about namespaces in general. For their use in computing, see Namespace (computer science).For their use in Wikipedia, see Wikipedia:Namespace.
In general, a namespace is a container that provides context for the identifiers (names, or technical terms, or words) it holds, and allows the disambiguation of homonym identifiers residing in different namespaces.[1]
For many programming languages, a namespace is a context for their identifiers. In an operating system, an example of namespace is a directory. Each name in a directory uniquely identifies one file or subdirectory, but one file may have the same name multiple[2] times.
The namespace consists generally of words separated by a period ('
.
'). Although the namespace notation resembles the library notation in Java at a first glance, it differs semantically. So, if you write in Javajava.servlet.http
, you are using this library; writingjava.servlet.*
would include alsohttp
and any other sublibraries ofservlet
. This is not the case in namespaces, where a period and asterisk (.*
) at the end is not allowed.As a rule, names in a namespace cannot have more than one meaning; that is, different meanings cannot share the same name in the same namespace. A namespace is also called a context, because the same name in different namespaces can have different meanings, each one appropriate for its namespace.
Following are other characteristics of namespaces:
- Names in the namespace can represent objects as well as concepts, be the namespace a natural or ethnic language, a constructed language, the technical terminology of a profession, a dialect, a sociolect, or an artificial language (e.g., a programming language).
- In the Java programming language, identifiers that appear in namespaces have a short (local) name and a unique long "qualified" name for use outside the namespace.
- Some compilers (for languages such as C++) combine namespaces and names in a process called name mangling.
Below is an example of a namespace in C++:
namespace Box1{ int boxSide = 4; } namespace Box2{ int boxSide = 12; } int main () { cout << Box1::boxSide << endl; //output 4 cout << Box2::boxSide << endl; //output 12 return 0; }
See also
- 11-Digit Delivery point ZIP code
- Binomial nomenclature (genus-species in biology)
- Chemical nomenclature
- Dewey Decimal Classification
- Digital object identifier
- Domain name system (DNS) names (Internet addresses)
- IP address
- Library of Congress Classification
- Category:National identification numbers
- Star catalogues and astronomical naming conventions
- XML Namespaces
References
- ^ "C# FAQ: What is a namespace". http://en.csharp-online.net/: C# Online Net. http://en.csharp-online.net/CSharp_FAQ:_What_is_a_namespace. Retrieved 2010-02-23. "A namespace is nothing but a group of assemblies, classes, or types. A namespace acts as a container—like a disk folder—for classes organized into groups usually based on functionality. C# namespace syntax allows namespaces to be nested."
- ^ "C# FAQ: What is a namespace". http://en.csharp-online.net/: C# Online Net. http://en.csharp-online.net/CSharp_FAQ:_What_is_a_namespace. Retrieved 2010-02-23. "For instance, [under Windows], to access the built-in input-output (I/O) classes and members, use the System.IO namespace. Or, to access Web-related classes and members, use the System.Web namespace."
Categories:- Naming conventions
- Computer programming stubs
Wikimedia Foundation. 2010.