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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With