[MUSIC]
>> Greetings everyone and welcome back to
Microsoft's Java for Beginners Series.
My name is Brian Benz.
I'm a Cloud Advocate at Microsoft.
I'm once again joined by
Kirk Pepperdine who's going to talk to us about Part
3 on the topic of Classes and Packages.
Kirk, do you want to tell us a little
bit more about what we're talking?
>> Thank you, Brian. In this final segment,
we'll look at how fully qualified class name's form A namespace in
the runtime and then how that helps us avoid namespace collisions.
>> The final bit of the story is a little bit more about
the namespace that the fully qualified class names make.
In this case,
what I'm going to do is I'm going to go down into
the source directory and
we're just going to copy the person class up into new package.
I'm going to go into the column and I'm going to
make a util directory.
Sorry. Typing funk. Now,
what I'm going to do is I'm going to copy from
the model directory,
this is a person.javaclass.
I'm going to drop that into the util directory.
Now, at this point you might say,
we just have two identical classes,
but simply in separate packages.
What would happen now is if I compile both of these classes,
then the class that I compiled last would
overwrite the class that got compiled first,
and what would happen in that case,
that's an unpredictable result because
you generally don't know
which class is going to be compiled before the other.
That's because the fully qualified names are still the same,
and as we saw in the initial demo,
if we just compile a source file,
it's just going to use the fully qualified name to
create the directory structure that
we need and it's going to put the class file down there.
It doesn't really care if there's a class file there or not,
it's just going to overwrite it.
What we want to do in this particular case is we want to go in,
and what we'd like to do is just to make sure that we change
the fully qualified name to
match the directory structure that we're in.
Now, we can back up,
I think, one more to get to here.
I'm going to go into the classes directory
and into rm minus fr star.
It's nothing there anymore.
I can get rid of our person.jar.
We're just left with all of our artifacts,
so we can take a look at that and see.
Now, I can do a Java C
minus D classes because that's where
we want the compiler output to go.
In this case, what I need to do is I need to
specify all of the classes here,
so here I can do just star.java.
That will pick up all of the classes in
that package and then I can specify
again src/com/util*.java and that
will pick up all of the Java files in that directory.
We can run either class and you can see
that we're going to
get the results that we absolutely expect in this case.
If you want a real world example of this,
I would suggest that you look at
the JDK classes, Java/util.date and Java/SQL.date.
If you look at these classes,
you'll find that they have a different representation of
date that is best suited for their own particular purpose.
I hope that you found this presentation
useful and I would encourage you to
watch the other presentations in this series.
>> Thanks, Kirk. That was really great.
That concludes the topic of Classes and Packages for the series.
Please check out the rest of
the topics in Microsoft's Java for Beginners Series.
[MUSIC]