package and jar files  
Author Message
Developper





PostPosted: 2005-3-6 19:54:00 Top

java-programmer, package and jar files Hi,

I am new to Java. I hope someone can give me a hint.

What is the difference between package and jar files and do you use them ?

thanks

John


 
Oscar kind





PostPosted: 2005-3-6 21:25:00 Top

java-programmer >> package and jar files Developper <email***@***.com> wrote:
> I am new to Java. I hope someone can give me a hint.

Two notes in this regard:
1. comp.lang.java.help is more appropriate for questions like these.
2. If you haven't already, try and find some tutorials and/or books to
explain the basics to you. There have been some threads to this very
topic recently.


> What is the difference between package and jar files and do you use them ?

A package is the equivalent of a .NET or C++ namespace, organized into a
directory structure.

For example, I frequently try stuff in a simple class called JavaTest.
This class is placed in the package nl.opk, so the directories the source
and code of this class in my project are:
<project directory>/source/nl/opk/JavaTest.java
<project directory>/source/nl/opk/JavaTest.class

To use a package, put a line like this as first non-empty non-comment line
in your file:
package my.package;

Also make sure the file is in the correct directory (see above).


A .jar file is an archive. In fact, it's a .zip file with a META-INF
directory with a MANIFEST.MF file in it. It can contain anything, which
includes classes (inside the directories that describe their packages). It
can also include source code, javadoc documentation and/or other resources
(files).

.jar files are created using the jar tool supplied with the JDK/SDK.
.jar files are used by placing them in the classpath, or by starting java
with the -jar switch. Read the manuals of "jar" and "java" for more info.


--
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website

PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
 
Rhino





PostPosted: 2005-3-6 21:57:00 Top

java-programmer >> package and jar files
"Developper" <email***@***.com> wrote in message
news:422aef35$0$44091$email***@***.com...
> Hi,
>
> I am new to Java. I hope someone can give me a hint.
>
> What is the difference between package and jar files and do you use them ?
>
In brief, a JAR file is a physical file, structured much like a zip file,
that contains files used by your program at execution time. A jar will
typically include .class files, the executable versions of your classes, and
other resources like icons, pictures, language-specific properties files,
etc. The Java Tutorial describes jars, and how to create/manage them.
(http://java.sun.com/docs/books/tutorial/jar/index.html)

Packages are defined like this in the Java Tutorial trail on interfaces and
packages: "A collection of related classes and interfaces providing access
protection and namespace management."
(http://java.sun.com/docs/books/tutorial/java/interpack/). While accurate, I
don't find that this definition, by itself, really gives you a good sense of
what a package is. For more information, go to the cited page and read
within that section of the tutorial.

Rhino