WEBVTT

00:00.080 --> 00:00.620
Hi everyone.

00:00.620 --> 00:01.190
Welcome back.

00:01.190 --> 00:07.430
In this lecture we are going to learn about how to build a modular application using the Jpms.

00:07.430 --> 00:11.120
So for this specific section we'll be working on the modules project.

00:11.120 --> 00:17.120
So if you open the modules project it will have four different modules module one, module two, module

00:17.120 --> 00:18.470
three and module four.

00:18.470 --> 00:22.430
For this specific lecture we are going to be working on the module one.

00:22.520 --> 00:25.460
Expand this project and then you will have a source directory over here.

00:25.460 --> 00:30.230
And then in here you will have these different packages inside this module one.

00:30.230 --> 00:35.900
And then if you take a look at it this one has a Dtos which is module one DTO which is a very simple

00:35.900 --> 00:37.490
module record type.

00:37.490 --> 00:43.340
In this case the name of this one is module one DTO and it is of type record and it has only one property

00:43.370 --> 00:44.630
named name.

00:44.630 --> 00:49.820
And if you take a look at the HTTP package we have HTTP client class is really empty.

00:49.850 --> 00:52.190
It just have an instance of the client over here.

00:52.190 --> 00:54.230
And if you take a look at the secret package.

00:54.230 --> 00:59.660
So this is has a secret class and it returns a secret using the secret function.

00:59.660 --> 01:03.230
And then we have another package named module one service.

01:03.230 --> 01:06.950
So this one actually has a function named Retrieve Data.

01:06.950 --> 01:10.250
And then this is the one which returns a module one DTO.

01:10.250 --> 01:12.830
So this is all about this particular module.

01:12.830 --> 01:17.360
What we are going to do here is that we are going to make this specific project to be modular.

01:17.360 --> 01:21.650
So we are going to use the Jpms concepts and then make this project to be modular.

01:21.650 --> 01:26.930
So very first thing in order to make this project modular, what we need to do is we need to add a class

01:26.930 --> 01:29.570
named module Hyphen Info dot Java.

01:29.570 --> 01:31.700
So I'm going to right click on the Java folder.

01:31.700 --> 01:33.380
And then I'm going to create a file.

01:33.380 --> 01:36.380
So you need to have the option selected as file over here.

01:36.380 --> 01:42.860
And then we are going to mark this file name as module hyphen info dot Java okay.

01:42.890 --> 01:44.900
So this is the name that you need to provide.

01:44.900 --> 01:47.480
And you can see this is a regular Java file.

01:47.480 --> 01:49.880
And the code will compile without any issues.

01:49.880 --> 01:54.050
And one thing you need to make sure is this needs to be just below the Java directory.

01:54.050 --> 01:57.470
So after this what I'll do is I'll quickly do a refresh over here.

01:57.500 --> 02:02.330
Just to make sure the change that we made is going to be reflected in our workspace.

02:02.360 --> 02:06.710
As you can see, the model refresh is happening over here and it just got completed.

02:06.710 --> 02:11.720
And then what I'm going to do is that I'm going to be introducing you to the modular concepts now.

02:11.720 --> 02:16.610
So the very first thing is in order to define a module you need to create a module like this.

02:16.610 --> 02:19.010
And then you have to give a name for this module.

02:19.010 --> 02:23.300
So I'm going to name this one as module one and then open and close parentheses.

02:23.600 --> 02:28.310
So once this change is done you might be noticing there is a compilation issue right.

02:28.310 --> 02:31.220
So this one is complaining about something.

02:31.220 --> 02:35.750
This was working until now but we started seeing this problem.

02:35.750 --> 02:37.670
Let's go ahead and open this HTTP client.

02:37.670 --> 02:42.320
And then what it says is that if I mouse over on that one package Java dot.

02:42.320 --> 02:47.060
Net dot HTTP is declared in module, but module does not read it.

02:47.060 --> 02:49.820
So this means we need to explicitly add that module.

02:49.820 --> 02:50.300
Let's see.

02:50.300 --> 02:52.670
The IntelliJ is giving the recommendation.

02:52.670 --> 02:55.580
The IntelliJ is giving the recommendation to add this one.

02:55.580 --> 02:56.630
So this is what I said.

02:56.630 --> 03:01.790
Any time you use a code that's not part of the base, the IDE has the ability to tell you what you need

03:01.790 --> 03:03.170
to do in order to make this work.

03:03.200 --> 03:04.640
So in this case, select this one.

03:04.640 --> 03:09.050
And then if you go to the module file you will notice this specific directive added.

03:09.050 --> 03:11.510
So in this case it is requires Java dot.

03:11.660 --> 03:12.680
Net dot HTTP.

03:12.710 --> 03:17.720
This is to make sure the HTTP module is available for our specific project.

03:17.720 --> 03:21.980
So if you want a quick reference on the actual hierarchy if you go here.

03:21.980 --> 03:24.770
So base is what that comes with out of the box.

03:24.770 --> 03:27.710
So we don't have to add any additional module.

03:27.710 --> 03:32.270
As soon as you add that module in for Java the base automatically comes with it.

03:32.270 --> 03:35.990
But HTTP is something which is not going to come out of the box.

03:35.990 --> 03:39.260
So you need to explicitly define hey, I need this specific module.

03:39.260 --> 03:41.570
So make that module available for my project.

03:41.570 --> 03:43.970
So that's exactly what we did over here.

03:43.970 --> 03:49.550
So in order to make that work you need to provide the requires and then provide that base module or

03:49.550 --> 03:51.230
the module that you need actually.

03:51.230 --> 03:55.160
So this is the first thing you need to know about when you are using modular project.

03:55.160 --> 03:59.360
So the next concept that I'm going to introduce you to is that it's going to be exports.

03:59.360 --> 04:02.030
So in this case I have four packages here.

04:02.030 --> 04:02.240
Right.

04:02.240 --> 04:06.170
I have Dtos http secret and service.

04:06.170 --> 04:11.750
So let's say I don't want to be exposing this secret service at all, because by default none of these

04:11.750 --> 04:14.840
packages will get exported unless and until you call it out.

04:14.840 --> 04:20.690
So you need to explicitly call out what this project is going to export or this library is going to

04:20.720 --> 04:21.110
export.

04:21.110 --> 04:25.640
So in this case I want to export comm dot module one dot Dtos.

04:25.670 --> 04:27.770
I want to export this specific package.

04:27.830 --> 04:32.810
When I say export, when you publish this as a library, these package and the classes that's inside

04:32.810 --> 04:35.870
this package is going to be visible to the user of this library.

04:35.870 --> 04:38.660
So the next thing that I'm going to export is a service.

04:38.660 --> 04:43.850
And the next thing that I'm going to export is a HTTP or I don't want HTTP to be exported, so I just

04:43.850 --> 04:46.100
want to export just these two packages.

04:46.100 --> 04:50.060
So this is how you make your code visible to the outside world.

04:50.090 --> 04:56.600
So when you build a Jar file The jar file is just going to have this dto's and the service package and

04:56.600 --> 04:58.190
the classes under those packages.

04:58.190 --> 05:04.430
So this is the first look at how do you build a modular Java application using the modules concept.

05:04.430 --> 05:10.190
So what we learned in this particular lecture is that we learned about how do you add additional modules

05:10.190 --> 05:14.240
other than the Java base by using this requires directive.

05:14.240 --> 05:19.670
And number two is we learned about how do you export packages from this particular project to the outside

05:19.670 --> 05:26.330
world, or any other client library that's going to use module one as a dependency using the exports

05:26.330 --> 05:26.900
directive.

05:26.900 --> 05:29.660
So with this information, I'm going to wrap up this specific lecture.

05:29.660 --> 05:35.270
In the next lecture we will learn about how do you use module one as a dependency to the other module.

05:35.270 --> 05:39.260
So basically we are going to learn about how to work with multiple modules.

05:39.260 --> 05:42.380
When you have a modular project like this is available.

05:42.380 --> 05:44.810
I hope you all were able to successfully implement this.

05:44.840 --> 05:49.460
If you have any questions or clarifications, please don't hesitate to write it in Q&amp;A.

05:49.490 --> 05:50.900
I would be happy to help.
