Code and commands from OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide:: Exam 1Z0-815 by Jeanne Boyarsky and Scott Selikoff
The code in chapter 11 (modules) is a lot of file creation. Additionally, the commands are hard to type in. Therefore we are providing a repository with the code from the book to facilitate running the example.
Also see:
- Our main book page
- To buy the book: Amazon
Below is an outline of the chapter and the commands. Note that in this github repo, the commands are one line so you can copy/paste them into your command line. In the book, we used multiple lines for ease in reading/studying.
Note: You may have to create the "mods" directory before running depending on your OS
See the feeding folder for module zoo.animal.feeding
Compile program
javac --module-path mods -d feeding feeding/zoo/animal/feeding/*.java feeding/module-info.java
Alternate forms of javac command
javac -p mods -d feeding feeding/zoo/animal/feeding/*.java feeding/*.java
javac -p mods -d feeding feeding/zoo/animal/feeding/*.java feeding/module-info.java
javac -p mods -d feeding feeding/zoo/animal/feeding/Task.java feeding/module-info.java
javac -p mods -d feeding feeding/zoo/animal/feeding/Task.java feeding/*.java
Run program
java --module-path feeding --module zoo.animal.feeding/zoo.animal.feeding.Task
Alternate form of java command
java -p feeding -m zoo.animal.feeding/zoo.animal.feeding.Task
Create jar
jar -cvf mods/zoo.animal.feeding.jar -C feeding/ .
Run program from jar
java -p mods -m zoo.animal.feeding/zoo.animal.feeding.Task
See the feeding folder for module zoo.animal.feeding. Uncomment the commented out line in module-info.java
Re-compile:
javac -p mods -d feeding feeding/zoo/animal/feeding/*.java feeding/module-info.java
Re-package
jar -cvf mods/zoo.animal.feeding.jar -C feeding/ .
See the care folder for module zoo.animal.care
Compile:
javac -p mods -d care care/zoo/animal/care/details/*.java care/zoo/animal/care/medical/*.java care/module-info.java
Package:
jar -cvf mods/zoo.animal.care.jar -C care/ .
See the talks folder for module zoo.animal.talks.
Compile:
javac -p mods -d talks talks/zoo/animal/talks/content/*.java talks/zoo/animal/talks/media/*.java talks/zoo/animal/talks/schedule/*.java talks/module-info.java
Package:
jar -cvf mods/zoo.animal.talks.jar -C talks/ .
See the staff folder for module zoo.staff.
Compile:
javac -p mods -d staff staff/zoo/staff/*.java staff/module-info.java
Package:
jar -cvf mods/zoo.staff.jar -C staff/ .
In the module-info.java in the talks folder:
- Uncomment
exports zoo.animal.talks.content to zoo.staff;
- Comment out
exports zoo.animal.talks.content;
In the module-info.java in the care folder:
- Uncomment
requires transitive zoo.animal.feeding;
- Comment out
requires zoo.animal.feeding;
In the module-info.java in the talks folder:
- Uncomment
requires transitive zoo.animal.care;
- Comment out
requires zoo.animal.feeding;
- Comment out
requires zoo.animal.care;
In the module-info.java in the staff folder:
- Comment out
requires zoo.animal.feeding;
- Comment out
requires zoo.animal.care;
Don't need to be able to use in examples for this exam
Describing a module:
java -p mods -d zoo.animal.feeding
Alternate form of describing a module
java -p mods --describe-module zoo.animal.feeding
Listing available modules in JDK:
java --list-modules
Listing available modules including ours:
java -p mods --list-modules
Showing Module Resolution:
java --show-module-resolution -p feeding -m zoo.animal.feeding/zoo.animal.feeding.Task
Describing a module:
jar -f mods/zoo.animal.feeding.jar -d
Alternate form of describing a module:
jar --file mods/zoo.animal.feeding.jar --describe-module
Listing dependencies
jdeps -s mods/zoo.animal.feeding.jar
Alternate form of listing dependencies:
jdeps -summary mods/zoo.animal.feeding.jar
Listing dependencies with module path
jdeps -s --module-path mods mods/zoo.animal.care.jar
Alternate form of listing dependencies with module path
jdeps -summary --module-path mods mods/zoo.animal.care.jar
Don't need to be able to use in examples for this exam