Skip to content
Advertisement

Difference between namespace in C# and package in Java

What is the difference (in terms of use) between namespaces in C# and packages in Java?

Advertisement

Answer

From: http://www.javacamp.org/javavscsharp/namespace.html


Java

Packages are used to organize files or public types to avoid type conflicts. Package constructs can be mapped to a file system.

JavaScript

may be replaced:

JavaScript

There is no alias for packages. You have to use import statement or fully-qualified name to mention the specific type.

JavaScript

or

JavaScript

Another source file:

JavaScript

Package cannot be nested. One source file can only have one package statement.

C#

Namespaces are used to organize programs, both as an “internal” organization system for a program, and as an “external” organization system.

JavaScript

may be replaced:

JavaScript

Alternatively, one could specify an alias for the the namespace, eg

JavaScript

and then refer to the class with

JavaScript

or

JavaScript
Advertisement