views:

122

answers:

3

I'm familiar with .Net and what assemblies are - but sadly my Java knowledge isn't as strong.

I know Java and .Net are different "worlds" (possibly like comparing apples with pears) but are JARs and .Net Assemblies roughly eqivalent concepts?

Edit: Update base on initial responses

The way I interpret this is that yes they have similarities:

  • Both can contain resources and metadata.

But there's some core differences:

  • a .Net assembly is compiled a JAR isn't.
  • JAR files aren't required to make a Java application; .Net assemblies are required for a .Net application.

[This isn't time for a religious war - I'd like to know if / how much of my understanding of .Net Assemblies I can apply to getting my head around Java (and maybe this will even help Java folks going the other way).]

+2  A: 

There's a bunch of technical differences, but they are of little consequence most of the time, so basically, YES, they are the same concept.

James Curran
Thanks; I can see why you've said they're the same concept.
Adrian K
+2  A: 

I would say no, they are not the same concept, noting that a JAR can be used like an assembly. If you really want to get your head around a JAR file, just think of it as a ZIP file. That's all it really is.

Most often, that archive contains compiled class files. And most often, those class files are arranged in a hierarchal fashion corresponding to the class's package.

But JAR files frequently contain other stuff, such as message bundles, images, and even the source files. I'd encourage you to crack one open with the unzip client of your choice and take a look inside.

The JAR format is however the most common way of packaging a distributable for a Java library or application so in that way they are very similar.

From a language standpoint, JAR files are in no way required to make a Java application or library, nor would I say they are intrinsic to Java, however both the standard library and the JDK has support for dealing with JAR files.

Mark Peters
"Most often, that archive contains compiled class files." - does that mean it doesn't always have to?
Adrian K
@Adrian K: Right, it doesn't have to. For instance, the compiled files, doc files and source files for a library will often be distributed in 3 different jar files, though there's really no specific need for sources and docs to be in a jar rather than a plain .zip.
ColinD
+1  A: 

At one level, they are conceptually similar (chunk of byte code in a package). However, their implementation is very different.

A JAR file is actually a ZIP file containing some metadata, and all of the Java .class files (yes you can actually open it as a ZIP file and see inside), and whatever else was packaged up in it (resources, etc).

A .NET assembly is actually a valid Win32 PE file, and can be treated as such to some extent. A .NET .exe file actually begins executing as native code which loads the framework, which then load the bytecode. "Executing" a JAR file requires launching the Java runtime through a .bat file, or file association, which then loads the JAR file separately.

Bob