Hi everyone.
Welcome back.
In this lecture I'll introduce you to the new concept named Java Platform Module System or Jpms or Project
Jigsaw.
So these are the different terms you might hear if you are learning about Java Platform module system.
So this lecture is going to be a theory lecture where I'm going to explain about why this was introduced
in Java nine.
As I said, this concept got introduced in Java nine.
But the fundamental idea of Jpms is to package and deploy your applications in a better way.
That's a concept of using the Jpms in your application.
So the next basic question that might be running in your head is that why was this needed in the Java
ecosystem in the first place?
The very first reason is to modularize the JDK.
So what do I mean by that?
So until Java eight we used to have the jar file which holds all the necessary runtime libraries or
classes to run a Java applications.
But in most cases we don't need everything.
For example, let's say you are building a RESTful API, okay?
Which is very common in today's software development.
You don't need the classes under the applet package to be loaded into the JVM, right?
We don't even reference anything when you are building a RESTful API.
So by modularizing the JDK, the app can control on adding just the modules the app requires.
So that's the advantage with modularizing the JDK, so that you get to pick and choose what you want.
We will code and explore how to do this as we go further in this section, let me quickly show you how
the modularized JDK looks like.
So on the left I have the reference or representation of how the Jar file looks like until Java eight.
From Java nine, any code that you are running beyond Java nine uses the modular approach.
So in this case, the whole JDK is structured as modules, and each module holds a specific set of code
that the application can import into it.
You might have many questions on your head on how would I achieve that from a coding perspective?
You just got to wait until we get to the coding lectures will be exploring all these concepts.
Another important reason for introducing modularity is to enable secure coding.
By default, public is too open, which means any class that has a public modifier in it.
Then any other class can actually access or extend another class and then start using it.
But with the modules, we have a new restrictive controls to restrict access to certain internal classes.
You can also define which classes are visible to the outside world.
Which classes are going to be just visible to the module.
For example, we can actually control the packages in a library that can be exposed to the client.
This means we can make certain packages invisible to the users of the library.
And another reason is in today's world, any class can be accessed at runtime using reflection, and
then we can modify the behavior.
But using modules but using modules, we can restrict reflection during runtime.
Now let's discuss about the benefits of Jvms or modules.
We are going to have smaller jar file, which basically means we are going to have a reduced memory
footprint and possibly we will have an improved application startup time.
We will still have a clear separation of boundaries with introduction of modules where each module owns
certain responsibilities.
We will also have stricter access control, which is a new way of restricting access to certain internal
classes, which was never intended to be used by others.
So with this information in place, let's quickly take a look at the modules that we have been using
already so far without our knowledge.
I'm going to go back to IntelliJ and then show you those modules, and there is a hierarchy of how those
modules are connected.
I will show that information too.
So let's go back to IntelliJ.
So in the IntelliJ.
So this is a code base we have been working so far.
Let me close all the tabs here.
There you go.
And in here if you minimize all the projects you will notice something called external libraries.
Over here if you expand this one.
And if you expand the JDK that we have been using so far.
So in here you see right, we have been using these modules.
So if you take a look at it, we have a Java based Java compiler desktop logging.
You have many different modules that are part of it.
So whatever that starts with Java Dot, those are specifically used by the application code.
And JDK is something which will be used by the Java platform, which means the Java runtime.
Okay.
So let's quickly take a look at what we have in the base package.
If you open the base package, this is where all the Java.lang class files and all those things sit
actually.
So if you expand Java and if you expand and if you can expand Lang to see whether the string classes
are there, if you go a little bit down, you may be able to find the string class.
So string class is something which is very popular.
So we normally use it on a day to day basis.
Right.
So all these classes which are the base requirement to run a Java application are part of this Java
base module.
And then you have other modules too.
So you have the SQL one as a separate module altogether.
And you have XML one which is a separate module altogether.
So in this case, let's say you're building a code which doesn't require any kind of DB interaction
or XML.
Then you can ignore those libraries and just use the base, which should take care of automatically
loading the dependencies for you so that you can build your application.
So if you are looking for a complete view of how these modules are connected.
So I'm going to go back to the browser.
So in the browser so you can see this specific link I'll be sharing this link and I'll attach it to
this lecture.
So in here if you click on this one.
So it will actually show you the complete view of how the different modules are connected.
But number one is the Java base.
So all the other modules that are part of the Java platform module system actually reference base.
As you can see all these modules use it Java.net dot HTTP.
It also uses base.
And if you think about the SQL one it requires XML.
And then that again indirectly depends upon base.
So this is the hierarchy tree if you're interested in learning about it.
But from a developer perspective you don't need to know each and every module and how it's connected.
It's based on what application you build.
You'll be getting recommendations from the IntelliJ itself when you start coding these concepts.
I hope the explanation is clear.
With this information, we will start building some modular applications using Java Platform Module
system.
This marks the end of this lecture.
Thank you for watching.