WEBVTT

00:00.050 --> 00:00.590
Hi everyone.

00:00.590 --> 00:01.400
Welcome back.

00:01.400 --> 00:09.110
In this lecture I'll introduce you to the new concept named Java Platform Module System or Jpms or Project

00:09.140 --> 00:09.710
Jigsaw.

00:09.710 --> 00:15.890
So these are the different terms you might hear if you are learning about Java Platform module system.

00:15.890 --> 00:21.410
So this lecture is going to be a theory lecture where I'm going to explain about why this was introduced

00:21.410 --> 00:23.270
in Java nine.

00:23.300 --> 00:27.530
As I said, this concept got introduced in Java nine.

00:27.530 --> 00:34.190
But the fundamental idea of Jpms is to package and deploy your applications in a better way.

00:34.190 --> 00:38.420
That's a concept of using the Jpms in your application.

00:38.420 --> 00:44.120
So the next basic question that might be running in your head is that why was this needed in the Java

00:44.150 --> 00:45.680
ecosystem in the first place?

00:45.680 --> 00:49.040
The very first reason is to modularize the JDK.

00:49.040 --> 00:50.450
So what do I mean by that?

00:50.450 --> 00:58.880
So until Java eight we used to have the jar file which holds all the necessary runtime libraries or

00:58.880 --> 01:01.070
classes to run a Java applications.

01:01.070 --> 01:03.950
But in most cases we don't need everything.

01:03.950 --> 01:07.340
For example, let's say you are building a RESTful API, okay?

01:07.370 --> 01:09.950
Which is very common in today's software development.

01:09.950 --> 01:15.410
You don't need the classes under the applet package to be loaded into the JVM, right?

01:15.410 --> 01:18.770
We don't even reference anything when you are building a RESTful API.

01:18.800 --> 01:26.330
So by modularizing the JDK, the app can control on adding just the modules the app requires.

01:26.330 --> 01:32.330
So that's the advantage with modularizing the JDK, so that you get to pick and choose what you want.

01:32.360 --> 01:37.760
We will code and explore how to do this as we go further in this section, let me quickly show you how

01:37.760 --> 01:40.070
the modularized JDK looks like.

01:40.070 --> 01:46.850
So on the left I have the reference or representation of how the Jar file looks like until Java eight.

01:46.850 --> 01:52.490
From Java nine, any code that you are running beyond Java nine uses the modular approach.

01:52.490 --> 02:00.140
So in this case, the whole JDK is structured as modules, and each module holds a specific set of code

02:00.140 --> 02:02.630
that the application can import into it.

02:02.660 --> 02:07.220
You might have many questions on your head on how would I achieve that from a coding perspective?

02:07.250 --> 02:12.200
You just got to wait until we get to the coding lectures will be exploring all these concepts.

02:12.230 --> 02:17.510
Another important reason for introducing modularity is to enable secure coding.

02:17.510 --> 02:23.180
By default, public is too open, which means any class that has a public modifier in it.

02:23.180 --> 02:29.360
Then any other class can actually access or extend another class and then start using it.

02:29.360 --> 02:35.720
But with the modules, we have a new restrictive controls to restrict access to certain internal classes.

02:35.720 --> 02:39.680
You can also define which classes are visible to the outside world.

02:39.680 --> 02:43.250
Which classes are going to be just visible to the module.

02:43.250 --> 02:48.770
For example, we can actually control the packages in a library that can be exposed to the client.

02:48.770 --> 02:53.330
This means we can make certain packages invisible to the users of the library.

02:53.810 --> 02:59.690
And another reason is in today's world, any class can be accessed at runtime using reflection, and

02:59.690 --> 03:01.430
then we can modify the behavior.

03:01.430 --> 03:06.230
But using modules but using modules, we can restrict reflection during runtime.

03:06.230 --> 03:10.190
Now let's discuss about the benefits of Jvms or modules.

03:10.190 --> 03:15.620
We are going to have smaller jar file, which basically means we are going to have a reduced memory

03:15.620 --> 03:19.940
footprint and possibly we will have an improved application startup time.

03:19.940 --> 03:26.000
We will still have a clear separation of boundaries with introduction of modules where each module owns

03:26.000 --> 03:27.860
certain responsibilities.

03:27.920 --> 03:34.670
We will also have stricter access control, which is a new way of restricting access to certain internal

03:34.670 --> 03:37.850
classes, which was never intended to be used by others.

03:37.850 --> 03:42.440
So with this information in place, let's quickly take a look at the modules that we have been using

03:42.440 --> 03:44.390
already so far without our knowledge.

03:44.390 --> 03:49.910
I'm going to go back to IntelliJ and then show you those modules, and there is a hierarchy of how those

03:49.910 --> 03:51.020
modules are connected.

03:51.020 --> 03:52.790
I will show that information too.

03:52.820 --> 03:54.500
So let's go back to IntelliJ.

03:54.530 --> 03:55.550
So in the IntelliJ.

03:55.580 --> 03:57.710
So this is a code base we have been working so far.

03:57.740 --> 03:59.450
Let me close all the tabs here.

03:59.480 --> 04:00.410
There you go.

04:00.440 --> 04:05.720
And in here if you minimize all the projects you will notice something called external libraries.

04:05.720 --> 04:07.550
Over here if you expand this one.

04:07.550 --> 04:10.310
And if you expand the JDK that we have been using so far.

04:10.310 --> 04:13.610
So in here you see right, we have been using these modules.

04:13.610 --> 04:18.860
So if you take a look at it, we have a Java based Java compiler desktop logging.

04:18.860 --> 04:21.590
You have many different modules that are part of it.

04:21.590 --> 04:27.140
So whatever that starts with Java Dot, those are specifically used by the application code.

04:27.140 --> 04:32.390
And JDK is something which will be used by the Java platform, which means the Java runtime.

04:32.420 --> 04:32.780
Okay.

04:32.810 --> 04:35.690
So let's quickly take a look at what we have in the base package.

04:35.690 --> 04:41.240
If you open the base package, this is where all the Java.lang class files and all those things sit

04:41.270 --> 04:41.570
actually.

04:41.570 --> 04:46.910
So if you expand Java and if you expand and if you can expand Lang to see whether the string classes

04:46.910 --> 04:50.180
are there, if you go a little bit down, you may be able to find the string class.

04:50.180 --> 04:52.460
So string class is something which is very popular.

04:52.460 --> 04:54.860
So we normally use it on a day to day basis.

04:54.890 --> 04:55.190
Right.

04:55.220 --> 05:01.010
So all these classes which are the base requirement to run a Java application are part of this Java

05:01.340 --> 05:02.840
base module.

05:02.870 --> 05:04.430
And then you have other modules too.

05:04.430 --> 05:07.940
So you have the SQL one as a separate module altogether.

05:07.940 --> 05:10.880
And you have XML one which is a separate module altogether.

05:10.880 --> 05:15.290
So in this case, let's say you're building a code which doesn't require any kind of DB interaction

05:15.290 --> 05:16.250
or XML.

05:16.250 --> 05:21.380
Then you can ignore those libraries and just use the base, which should take care of automatically

05:21.380 --> 05:24.800
loading the dependencies for you so that you can build your application.

05:24.800 --> 05:28.970
So if you are looking for a complete view of how these modules are connected.

05:28.970 --> 05:30.650
So I'm going to go back to the browser.

05:30.650 --> 05:35.780
So in the browser so you can see this specific link I'll be sharing this link and I'll attach it to

05:35.810 --> 05:36.320
this lecture.

05:36.320 --> 05:38.450
So in here if you click on this one.

05:38.450 --> 05:42.980
So it will actually show you the complete view of how the different modules are connected.

05:42.980 --> 05:45.200
But number one is the Java base.

05:45.200 --> 05:50.870
So all the other modules that are part of the Java platform module system actually reference base.

05:50.870 --> 05:54.470
As you can see all these modules use it Java.net dot HTTP.

05:54.500 --> 05:55.850
It also uses base.

05:55.850 --> 05:59.450
And if you think about the SQL one it requires XML.

05:59.450 --> 06:02.720
And then that again indirectly depends upon base.

06:02.720 --> 06:06.140
So this is the hierarchy tree if you're interested in learning about it.

06:06.140 --> 06:11.180
But from a developer perspective you don't need to know each and every module and how it's connected.

06:11.180 --> 06:13.610
It's based on what application you build.

06:13.640 --> 06:18.290
You'll be getting recommendations from the IntelliJ itself when you start coding these concepts.

06:18.530 --> 06:19.940
I hope the explanation is clear.

06:19.940 --> 06:25.070
With this information, we will start building some modular applications using Java Platform Module

06:25.070 --> 06:25.460
system.

06:25.460 --> 06:26.840
This marks the end of this lecture.

06:26.840 --> 06:27.800
Thank you for watching.
