Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Java Packages, .NET Assemblies and .NET Namespaces and is a Java package the same as a .NET Namespace?

So my question is: What are Java Packages, .NET Assemblies and .NET Namespaces and is a Java package the same as a .NET Namespace?

I have used Google to get the following:

Java Package: Java Packages provide a way of organizing files into different directories according to their functionality, usability and as well as category that they should belong to. An example of a package is the JDK package.

.NET Assembly: A .NET assembly provides a fundamental unit to physical code grouping.

.NET Namespace: A .NET namespace provides a fundamental unit of logical code grouping.

I have read about them, but haven't really understood, can anyone please explain further?

like image 697
JHarley1 Avatar asked Jan 10 '11 14:01

JHarley1


People also ask

Is namespace same as package in Java?

Java packages are namespaces. They allow programmers to create small private areas in which to declare classes. The names of those classes will not collide with identically named classes in different packages.

Is package and namespace same?

Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. A namespace is designed for providing a way to keep one set of names separate from another.

Is assembly in C# same as package in Java?

Its better to think of a C# assembly as a sealed jar or an OSGI package. A Java package is closer to a C# namespace , although none of these concepts map across the two languages perfectly.

Is namespace is a package in C#?

Namespace in C# vs. As an alternative of Packages in Java, the C# language has namespace. The main usage of packages in Java is to control access, to prevent naming conflicts and also to make searching and usage of interfaces, classes, annotations and enumerations easier.


1 Answers

The difference between assembly and namespace is, as you've pointed out, that the former organizes code physically, and the latter logically. Assemblies are your DLL and EXE files. Namespaces are just the dot notation that'll help you find your classes as you write code.

A Java package is very similar to a .NET namespace. In Java, each public non-nested class needs to have its own *.java-file, and the packages must have their corresponding directories, so that's why you'll read references to directories when reading up on java packages, but not in .NET, as a single file can contain several .NET namespaces, and a single namespace can be scattered across several directories.

like image 141
David Hedlund Avatar answered Sep 23 '22 04:09

David Hedlund