ArticleslgStudy

computer science

JAR (file format)

JAR (file format) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand JAR (file format) rather than just read about it. In short: A JAR ("Java archive") file is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. JAR files are archive files that include a Java-specific manifest file.

JAR (file format) — main illustration
JAR (file format) — illustration

Key takeaways

  • JAR (file format) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect JAR (file format) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of JAR (file format) from memory before moving on to harder problems.

Reference excerpt

A JAR ("Java archive") file is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. JAR files are archive files that include a Java-specific manifest file. They are built on the ZIP format and typically have a .jar file extension.

Design A JAR file allows Java runtimes to efficiently deploy an entire application, including its classes and their associated resources, in a single request. JAR file elements may be compressed, shortening download times. A JAR file may contain a manifest file, that is located at META-INF/MANIFEST.MF. The entries in the manifest file describe how to use the JAR file. For instance, a Classpath entry can be used to specify other JAR files to load with the JAR.

Extraction The contents of a file may be extracted using any archive extraction software that supports the ZIP format, or the jar command line utility provided by the Java Development Kit.

Security Developers can digitally sign JAR files. In that case, the signature information becomes part of the embedded manifest file. The JAR itself is not signed, but instead every file inside the archive is listed along with its checksum; it is these checksums that are signed. Multiple entities may sign the JAR file, changing the JAR file itself with each signing, although the signed files themselves remain valid. When the Java runtime loads signed JAR files, it can validate the signatures and refuse to load classes that do not match the signature. It can also support 'sealed' packages, in which the Classloader will only permit Java classes to be loaded into the same package if they are all signed by the same entities. This prevents malicious code from being inserted into an existing package, and so gaining access to package-scoped classes and data. The content of JAR files may be obfuscated to make reverse engineering more difficult.

Executable JAR files An executable Java program can be packaged in a JAR file, along with any libraries the program uses. Executable JAR files have the manifest specifying the entry point class with Main-Class: myPrograms.MyClass and an explicit Class-Path (and the -cp argument is ignored). Some operating systems can run these directly when clicked. The typical invocation is java -jar foo.jar from a command line. Native launchers can be created on most platforms. For instance, Microsoft Windows users who prefer having Windows EXE files can use tools such as JSmooth, Launch4J, WinRun4J or Nullsoft Scriptable Install System to wrap single JAR files into executables.

Manifest A manifest file is a metadata file contained within a JAR. It defines extension and package-related data. It contains name–value pairs organized in sections. If a JAR file is intended to be used as an executable file, the manifest file specifies the main class of the application. The manifest file is named MANIFEST.MF. The manifest directory has to be the first entry of the compressed archive.

Specifications The manifest appears at the canonical location META-INF/MANIFEST.MF. There can be only one manifest file in an archive and it must be at that location. The content of the manifest file in a JAR file created with version 1.0 of the Java Development Kit is the following. Manifest-Version: 1.0 The name is separated from its value by a colon. The default manifest shows that it conforms to version 1.0 of the manifest specification. The manifest can contain information about the other files that are packaged in the archive. Manifest contents depend on the intended use for the JAR file. The default manifest file makes no assumptions about what information it should record about other files, so its single line contains data only about itself. It should be encoded in UTF-8.

Special-Purpose Manifest Headers JAR files created only for the purpose of archiving do not use the MANIFEST.MF file. Most uses of JAR files go beyond simple archiving and compression and require special information in the manifest file.

Features The manifest allows developers to define several useful features for their jars. Properties are specified in key-value pairs.

Applications If an application is contained in a JAR file, the Java Virtual Machine needs to know the application's entry point. An entry point is any class with a public static void main(String[] args) method. This information is provided in the manifest Main-Class header, which has the general form: Main-Class: com.example.MyClassName In this example com.example.MyClassName.main() executes at application launch.

Package Sealing Optionally, a package within a JAR file can be sealed, which means that all classes defined in that package are archived in the same JAR file. A package might be sealed to ensure version consistency among the classes in the software or as a security measure. To seal a package, a Name entry needs to appear, followed by a Sealed header, such as:

The Name header's value is the package's relative pathname. Note that it ends with a '/' to distinguish it from a filename. Any headers following a Name header, without any intervening blank lines, apply to the file or package specified in the Name header. In the above example, because the Sealed header occurs after the Name: myCompany/myPackage header with no intervening blank lines, the Sealed header applies (only) to the package myCompany/myPackage. The feature of sealed packages is outmoded by the Java Platform Module System introduced in Java 9, in which modules cannot split packages.

Package Versioning Several manifest headers hold versioning information. One set of headers can be assigned to each package. The versioning headers appear directly beneath the Name header for the package. This example shows all the versioning headers:

Multi-Release A jar can be optionally marked as a multi-release jar. Using the multi-release feature allows library developers to load different code depending on the version of the Java runtime. This in turn allows developers to leverage new features without sacrificing compatibility. A multi-release jar is enabled using the following declaration in the manifest:

Dependencies The MANIFEST.MF file can be used to specify all the classes that must be loaded for an application to be able to run. Note that Class-Path entries are delimited with spaces, not with the system path delimiter:

… excerpt ends here. Continue reading the full article.

Illustrations

JAR (file format) illustration

Worked examples

Example 1 — a first encounter with JAR (file format)

Start with the simplest possible case. Write down what JAR (file format) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to JAR (file format) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about JAR (file format) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of JAR (file format)

In research
JAR (file format) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses JAR (file format) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
JAR (file format) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Archive formats, Java (software platform), so understanding it makes those chapters shorter.
In everyday life
Look for JAR (file format) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “JAR (file format)” →

How to study JAR (file format) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what JAR (file format) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain JAR (file format) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is JAR (file format) in simple terms?

A JAR ("Java archive") file is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution. JAR files are archive files that include a Java-specific manifest file.

Why does JAR (file format) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study JAR (file format)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on JAR (file format).

Tags

  • Archive formats
  • Java (software platform)

Keep exploring