Modular Programming in Java 9 by Kothagal Koushik

Modular Programming in Java 9 by Kothagal Koushik

Author:Kothagal, Koushik [Kothagal, Koushik]
Language: eng
Format: azw3, epub
Tags: COM051210 - COMPUTERS / Programming / Object Oriented, COM051000 - COMPUTERS / Programming / General, COM051280 - COMPUTERS / Programming Languages / Java
Publisher: Packt Publishing
Published: 2017-08-29T04:00:00+00:00


Optimizing module imports

In the previous chapter, we created the GUI address viewer module that required the Java FX modules necessary for building the UI. Here's what the module descriptor looked like:

module packt.addressbook.ui { exports packt.addressbook.ui; requires java.logging; requires javafx.base; requires javafx.controls; requires javafx.graphics; requires packt.addressbook.lib; }

We'll now see that not all the modules imported are actually required, and we can optimize this list a bit, thanks to our new knowledge of transitive dependencies. Running java -d on javafx.controls gives us:

$ java -d javafx.controls module javafx.controls@9 ... requires transitive javafx.base requires transitive javafx.graphics

Turns out the javafx.base and javafx.graphics modules are transitive dependencies of javafx.controls already. So, any module that reads javafx.controls also reads javafx.base and javafx.graphics! So, we can remove those two modules and just declare our dependency on javafx.controls, since that module alone pulls in all the dependencies we need. Here's the updated module descriptor for packt.addressbook.ui:

module packt.addressbook.ui { exports packt.addressbook.ui; requires java.logging; requires javafx.controls; requires packt.addressbook.lib; }

You should be able to recompile and execute the UI module to make sure things still work just the same.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.