package and jar files

D

Developper

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
 
O

Oscar kind

Developper said:
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.
 
R

Rhino

Developper said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top