Difference between a jar file and a library in Java
Solution 1
to put things very simple : library is a collection of jars
You could like create a global library java-ee which contains all Java EE related jar files. Then you could use this global library in your different projects. It will be simpler to manage them; and adding in new projects.
Solution 2
A JAR serves the same function an an Assembly in the C#/.net world. It's a collection of java classes, a manifest, and optionally other resources, such as properties files.
A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs.
Solution 3
If well understood: A library is simply a folder that groups classes. For example in JDK, a library present there is a group of classes stored together.
If not mistaken a .jar file is a group of compiled classes in .class format and was created by Java creators so a program will be OS independent; which means within a JVM you will run your app in .jar format on a Linux, Windows, etc without re-coding tour app for various OSs.
Solution 4
A jar file is zip archive containing among other files, the java class files. A Netbeans library contains resources required by the project, including jar files.
Related videos on Youtube
Bo Persson
I have been a software developer for almost 40 years, using a variety of programming languages like COBOL, Pascal, Ada, C, assembly, and some scripting languages. Now very interested in following the development of C++17 and beyond.
Updated on September 19, 2022Comments
-
Bo Persson over 1 year
NetBeans
allows the programmer to add alibrary
and ajar
file.What is the difference between a jar file and a library? Is library similar to
GAC assembly
as inWindows
.There are similar questions, but they are way too specific and I was not able to understand the difference.
-
Edwin Dalorzo over 11 yearsI am not a Netbeans user but if it gives you the option of loading a JAR or a library then the library could refer to a native library (i.e. a dll). Java can also execute native code through JNI, and some Java applications require such libraries to be available in your project to work properly.
-
Premraj almost 9 yearsprobably duplicate stackoverflow.com/q/4411028/1697099
-
-
Eelke over 11 yearsand a library can also contain the source code for debugging and javadocs for in IDE documentation tooltips.
-
Admin over 11 years
jar
also groups classes..what is the difference then -
Juvanis over 11 yearsa library can contain a single jar, too. that is not a good explanation.
-
Admin over 11 yearsso
jar
file cannot containjar
files butlibrary
does..is it the difference..sorry if it sounds funny but am new to java -
Admin over 11 years@DelShekasteh what can be the difference then..am getting damn confused
-
Admin over 11 yearsbut those resources can also be in
jar
file..right..sorry if it sounds funny..new to java world -
Deepak Singhal over 11 yearsTheoretically yes, a library can contain a single jar too. But that is not the idea behind a library.
-
Deepak Singhal over 11 years@cSharper Yes theoretically a jar file can contain another jar too because jar is also like a zip file. But putting a jar inside a jar will not help in anyway; because classes inside that embedded jar will not be available.
-
Admin over 11 years@Deepak so classes inside that
embedded jar
will be available if we use library right! -
Deepak Singhal over 11 yearsIf we use library and put 10 jar files into it; yes all those jars will be available.
-
Admin over 11 yearsalso does lib only contains jar files
-
Deepak Singhal over 11 yearsLibrary doesnt have .jar extension. Library is not a concept of java as such. It is used by different IDEs or many other places; but core java doesnt have library concept.
-
John Ballard over 11 yearsYes you are correct. I was attempting to simplify the problem. In reality a jar is nothing more than a zip file with a different extension. The jar can contain whatever you put in there. There is a specific format that java likes things to be in. The library is nothing more than an "abstraction" that Netbeans (and other IDEs) have created to indicate a collection of jars (or more generically resources). Usually this is store in configuration with your project, e.g. an xml file. The notion of library is not specific to java or the sdk, rather it is specific to the IDE.