Is a Java package the equivalent of a .Net assembly?

后端 未结 5 990
一个人的身影
一个人的身影 2020-12-04 20:01

I am a .Net developer starting Java development for Android and would like to know if it\'s correct to think of Java packages like .Net assemblies.

相关标签:
5条回答
  • 2020-12-04 20:12

    A Java package is like a namespace in .NET.

    The equivalent to an assembly in Java is jar file.

    0 讨论(0)
  • 2020-12-04 20:15

    No, I think a Java package would be more similar to a namespace

    And an assembly would be more like a jar (I'm not so sure about this, as I'm much more familiar with Java than .Net... correct me if I'm wrong)

    0 讨论(0)
  • 2020-12-04 20:20

    Bear in mind that I'm far from a Java expert, but anyway, there it goes my take on this:

    As pointed out by other answers, a package is not the equivalent to an Assembly. However, I don't fully agree with the idea of a .jar being the equivalent to an Assembly. To me, a Java class (contained in a .class file) is closer to an Assembly than a .jar is. I'm saying this cause while the load unit for the CLR is the Assembly (which means all classes contained in that Assembly get loaded), the load unit for the JVM is a class (when the JVM needs a class, the ClassLoader does not load all the classes in the container jar, it just loads that specific needed class).

    You can read more about java class loading here: When does the JVM load classes?

    and here: http://www.lansa.com/support/notes/p0294.htm

    0 讨论(0)
  • 2020-12-04 20:29

    A package in Java usually means just a namespaces for classes and interfaces, which in reality means a specific directory structure. Sometimes a .jar file is also referred to as a package. This is probably the closest you get to an assembly. A .jar file can also contain other data like images, or basically an kind of file since it is just a zip again with some specific content structure.

    In any case: Usually when you read "package" in relation to "Java", some kind of namespaces (via folder structure, e.g.: com.mycompany.myproject) is meant. It doesn't help that some build tools refer to the process of building .jar file as "packaging" ;-)

    0 讨论(0)
  • 2020-12-04 20:31

    No.

    The best comparison would be with a Java ARchive (Jar) file. Java uses packages to control the namespace, and is very similar to C#'s Namespaces.

    Here is how I'd compare the environments

    Java                    .Net
    ====                    ====
    Class                   Class
    Package                 Namespace
    Jar                     Assembly
    
    0 讨论(0)
提交回复
热议问题