namespaces are used to prevent clashing between class and function names. In C++ or C#, when you declare a class or function or variable belonging to a specific namespace, you cannot use that class, function or variable outside of that namespace. For example, in C++, namespaces are referenced in a couple of different ways:
Code:
using namespace std; // you are now able to use things from the std namespace without prefixing them
Code:
using std::cout;
using std::cin;
using std::endl;
// you can now use cout, cin and endl without prefixing them
// however, other members of the std namespace still need the prefixes
Code:
// you must prefix cout, cin and all other members of the std namespace
What did I mean by prefix? This is what I mean by prefix:
Code:
std::cout << "Hello world!" << std::endl;
Also, packages in Java work similarly to namespaces in C# and C++. For example, the "java.lang" package is imported by default, just as you often need to include "using System;" at the top of a C# program to prevent you from needing to use "System.Console.WriteLine" and "System.Convert.ToInt32" and all of that. In C#, you use the using directive to use a namespace without the prefix. In Java, you use the import keyword to import a package to serve a similar (and convenient) purpose. In C++, there are a few ways to use the using keyword and you also need to include the appropriate header files. C++ is basically double the work, but it also has a purpose: prevention of code collision as well as making sure something exists before even trying to compile.
To answer your questions:
C# = namespace, Java = package (basically the same purpose)
a namespace (or package) is used to prevent complications with another person's work because you could name a class or a function with the same name, but the namespace will be different