Making Our Sample Project Modular Using JPMS

Basics of Java 9 Modularity (JPMS or Project Jigsaw) Chapter 3- Introducing Java 9's JPMS Basic Features for Modular Programming
9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.99
List Price:  €92.85
You save:  €27.85
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$105.96
List Price:  A$151.38
You save:  A$45.42
S$94.48
List Price:  S$134.98
You save:  S$40.50
HK$546.78
List Price:  HK$781.15
You save:  HK$234.36
CHF 63.33
List Price:  CHF 90.48
You save:  CHF 27.14
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.44
List Price:  NZ$166.35
You save:  NZ$49.91
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,492.21
List Price:  ₨27,847.21
You save:  ₨8,355
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$355.02
List Price:  B$507.19
You save:  B$152.17
R1,295.44
List Price:  R1,850.71
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪260.15
List Price:  ₪371.66
You save:  ₪111.51
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,713.01
List Price:  ¥15,304.96
You save:  ¥4,591.95
MX$1,187.73
List Price:  MX$1,696.83
You save:  MX$509.10
QR254.83
List Price:  QR364.06
You save:  QR109.23
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.65
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,773.40
List Price:  ISK kr13,962.60
You save:  ISK kr4,189.20
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.26
List Price:  ден5,712.05
You save:  ден1,713.78
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.01
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,334.28
List Price:  Ft36,193.38
You save:  Ft10,859.10
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
Already have an account? Log In

Transcript

Now that we know what was the problem in this JPS basics version three, and at the same time, we know what jpm is in Gemini and plus has to offer, let's have a second look at the same problem, but this time in a modular fashion. So as you want to be able to use something like access modifiers and delivery of packages, we're not going to put every chain this time in the same project, we're going to have a modular project composed of different modules. And we just distribute these packages among those modules. So this time, I'm going to be showing you the first module that we have which we have named these one j PMS basics for module one. So if you open up this module, it's basically the same thing I showed you in the previous video, you have curated the module and in here if you go to the src folder, as you see in here, it's composed out one package which is named Comm.

That is the cash courses and at the same time, we have these and the root whoever we have this module, info Java, we look at this one. It's composed Have a modular structure the name is calm that easy to catch courses, which is going to be the same name as the package we have in here. And as it says it's going to be exporting comm that is the cash the courses package inside this module to the other modules which require this module to be imported in order to be able to use the functionalities inside these package. So like the previous version, we have this course interface, which is going to be something like a common interface used by all the classes in this package, then we have draft course, which is implementing the course interface and as you see, it's just composed of basic things and one play method as you see in here, which is going to be simulating playing this course if somebody calls this play on any draft course it will be printing something like this draft video with this name is being played at the same time we have these published course as another class in the same package.

So this published course class implements course interface as well. And as you see in here, not only has a name, but also has length because this is a published course it's been done it's not draft anymore, it now could be used by the end users of our website. So the biggest difference is going to be in the play method. It not only prints the published video with this name is being played but also prints for how long because it's been set already because now we know that the course is published and it's finalized version again as you see in here the module is named calm, that is the canister courses and exports The only package it has at the time. So now let's switch to the second module. So in this project, we have a second module which is named j PMS basics for now this is module two, and inside the src folder First of all, we have these module dash info the Java if you look at this one for now, let's just focus on these lines.

The name has been said to come that is the cache that libraries because as you see in here we have two packages and what they have in common is the prefix calm that is the cache at libraries. There is a package comm that is the cash with libraries dot draft, there is another sub package with is published in the same package. As you see, that's why we have chosen this name to be the name of the module. And it says I require the previous module, which was in the project jvms basics for module one with this name calm that easy to catch courses. So this module says I require that module. And as you remember, again, the first module says, I'm going to be exporting these package Condor application courses to any module which requires me as this one, by the way, as we talked in the previous video, that's not the only thing you need to do in such an IV like Eclipse.

The other thing you need to do is to right click on the project, go to the build path, configure build path, and in this configuration, you need to make sure that under the project's tab, you have made jvms basics for module one being accessible. Why are the module path for these jvms basics for module two? So this is the second thing you need to do so that the first module could be accessed by these second module. So now let's get inside What we have in the libraries, we have these draft course libraries, as you see in here, which is a simple simulation of libraries of draft courses. As you seen here, we have used a list of draft courses, there is this hard coded method. In order to keep things simple.

We have added just two draft courses named Android and a scholar. Let's say we have these two draft courses, which we are still working on and they are not in their finalized published version. And then we have this play library method which is going to be calling the load library and for all the courses in the draft course library is going to be playing them. So it's obvious that this class needs draft course class in the previous module. That was why again, that we said require this one, either here or in the build configuration path in a second package. We haven't here comm that is the cache that libraries that publish have another class again, the same concept we have this publish course library which is composed of at least a published courses and is going to be the same kind of thing.

We have this course which is published by Say we have a course for Java, which is one and a half hours, we have another published course JavaScript which is 1.6 hours and then if we call this play library method is going to be loading the library with these two published courses and playing both of them. So, going back to these module, they actually input the Java in the second module again, as you see in here, we have said not only require this module, but also we allow the outside modules to access these two packages in this module. Again, this module not only requires this module, but also exports these two packages inside the current module, which obviously we need these companies to cash out libraries module to be used by the other modules which like to access the libraries. So the third module we have in this project is an independence module again, and as you see in here again, we have module dash info and in here we have said the name is called it is the cash tools dot player.

And then we have explicitly mentioned that this module requires candidates to cash Libraries. The reason is we have a package in here called easy to catch the tools dot player which inside here we have this internal player class, which is going to need both libraries either for the draft course or for the published courses because this is internal tool that we have for testing and playing videos as an example on our website is cache.com. And again, remember, not only we have set the module info to say we require the libraries module, but also again, we have come to this build paths. And we have set this one to be accessing the second module back into our player class as you see here. Now we are allowed to access whatever classes we had in the libraries module or the second module so we could play the courses all the courses including draft and publish and if we run this code, as you see the output shows that all the courses are going to be played for us either the draft ones for the published with the ones Now, so far, so good.

Let's go to the fourth module with a project named j PMS basics for module four. And if I expand this one, again, I have a source folder at the root wherever I have this module dash input Java. And if we look at this one, even this fourth module says I required a second module or the libraries module. And probably I don't need to repeat again that we have done the same kind of thing in the configuration path. So in here, we have just these tools dot player package, which is going to be some kind of tools we have given to the end user, not just for the admin, if I go inside the package, I have just one class user player. And as you see in here for now, let's forget about the comments I have been able to access whether I have in this module in these package or soft package in this class.

And I have been able to create an object based on these published course library and then play everything I have in that library. So if I run this one, it's going to be showing me these which seems logical because these are published causes and should be reviewed by the end user. Now the problem problem that we have is that not only we have access to this publish courses library, but also if we remove the comments on these lines that you're seeing here, because inside the module info, we have said, we required the whole libraries module. And inside the libraries module, we had said that we export both packages. So not only inside internal player, but also inside the user player, we're able to access draft courses list which is not desired. So if I run this one, it gives me this output that I've been able as an end user drawn not only the published videos, but also the draft videos as a solution.

As we have mentioned in here. What if we don't export this one, because this is going to be something like a package, which should be used just by the admin or the internal user, not the end user of the website. what the problem is, if I comment this out, then I save everything for the user player. It makes sense that we shouldn't have access to the package all through our course library, but even that one happens to The same for internal player it means that we are some kind of stock now we have access at the level of packages. And using these kind of thing we could say which packages need to be export and which packages are going to be required. But for our simple problem or the simple example we had from the beginning, the problem would be in this module if I export these two packages and save it will be accessible to both modules which need this module.

Either it's going to be discarded, easy to catch the tools or player or content is to catch the user the tools player and in the next video, we're going to talk about how we could solve this problem to have these to be accessible just by module three and not by module four.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.