Is there any difference between a JAR file and a package?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A package is a way to logically organize your classes. For example, you can declare
package com.foo;at the top of each source file that are related enough to reside in thecom.foopackage together. The Java compiler and runtime will also expect you to place such files in the pathcom/foo/, where the root of this path is a directory or JAR in your classpath.A JAR file lets you physically organize your classes. You can take any Java files (and their parent directories, respecting the directory structure discussed above) and store them in a JAR file. A JAR file may contain files belonging to multiple packages, and multiple JAR files may contain files that belong to the same package. So, a JAR file is largely a way to store multiple class files in a single physical file.
There are some other special characteristics of JAR files. For example, you can specify a
Main-Classvalue in the JAR manifest to designate which class is the entry point for an application, and you can seal packages in a JAR file, “which means that all classes defined in that package must be archived in the same JAR file.”