here is what we know so far
we know that your Java code
when it is compiled turns into class files
we know also that class files
if you like you can organize those
into packages or directories
the next step of course
is if you are working on a project
and you have three directories
for your code
project A,B, and C
but if you are working with dozens
or maybe hundreds of other programmers
and they all have their classes
in their packages
when all this code comes together
to release one product
how do you actually take all of these packages
and somehow organize those as well
so now we are talking about
not just your classes which is shown
on the left of the slide
but all of the classes say for example
for your teammate
so now we have a combined
if they have three different packages and
you have three
we have six different directories
there is a way to do this
that is to zip all these directories togethers
all the directories have in them class files
you zip these all together
into one file called a jar
you see the acronym in the middle of the slide here
J.A.R.
that stands for Java ARchive
you know that it is a Java acronym
if it has a J in there somewhere :)
and conceptually this make some sense
you could think of a jar as a you know like
a container in which
you are going to put a whole bunch of information
and then you are going to put a lid on it
so a way in which to zip all of your directories
into one file
is using a tool to them all into a file
called a jar file
alright
so now you have all your files in one file
there are a few advantages to this
one advantage is that
if your company now wants to distribute
all this code
you could distribute just one file
a jar file
the other advantage
remember Java's history
Java came about so people can write programs
that run on the internet
when you hit a web page
if that web page has on it not only HTML
which displays to you information
but Java code which would be interactive
for every class file you need to download
it needs to make a connection to the server
so most people are familiar with going
to web page and having it stop for a minute
says loading Java
it's downloading one file
a jar file
if the web page that you went to
had instead of a jar file
they had
say ten different class files
that you needed
your browser would need to connect
to the server ten times
so that is a lot of connections that
you'd make to this server
which takes up a fair amount of time
not to mention the time it takes
to download the files
so there are a number of advantages
to the jar file
one is that in a browser
you only have to make one connection
to the server
another advantage
is when you download
from the server
not just the fact that it is
just only one file
but the file is typically smaller
is that it is a compressed version
of all of your classes
and the third advantage is not just
i am using Java in browsers
but as a company if you wanted
to distribute executable code
you could distribute only one file if you'd like
and that's a jar file
ok
so that's a review of a .java file, a .class file,
packages, jar files, and the JVM itself