├── Chapter01 └── NewApi.java ├── Chapter02 ├── a_classes │ ├── Car.java │ ├── Chapter02Classes.java │ ├── Engine.java │ └── Vehicle.java ├── b_innerclass │ ├── Chapter02InnerClasses.java │ ├── Vehicle.java │ ├── Vehicle1.java │ └── Vehicle2.java ├── c_inheritance │ ├── a │ │ ├── Car.java │ │ ├── Chapter02Inheritance.java │ │ ├── Truck.java │ │ └── Vehicle.java │ ├── b │ │ ├── Car.java │ │ ├── Chapter02Inheritance.java │ │ ├── Truck.java │ │ └── Vehicle.java │ ├── c │ │ ├── Car.java │ │ ├── Chapter02Inheritance.java │ │ ├── Truck.java │ │ └── Vehicle.java │ ├── d │ │ ├── Car.java │ │ ├── Chapter02Inheritance.java │ │ ├── Truck.java │ │ └── Vehicle.java │ └── e │ │ ├── Car.java │ │ ├── Chapter02Inheritance.java │ │ ├── Truck.java │ │ └── Vehicle.java ├── d_composition │ ├── Car.java │ ├── Chapter02Composition.java │ ├── SpeedModel.java │ ├── Truck.java │ └── Vehicle.java ├── e_interface │ ├── a │ │ ├── Chapter02Interface.java │ │ ├── FactorySpeedModel.java │ │ ├── FactoryVehicle.java │ │ └── api │ │ │ ├── Car.java │ │ │ ├── SpeedModel.java │ │ │ ├── Truck.java │ │ │ └── Vehicle.java │ └── b │ │ ├── Chapter02Interface.java │ │ ├── FactoryVehicle.java │ │ └── api │ │ ├── Car.java │ │ ├── SpeedModel.java │ │ ├── Truck.java │ │ └── Vehicle.java ├── f_optional │ └── OptionalDemo.java └── g_objects │ └── ObjectsDemo.java ├── Chapter03 ├── 10_compiling_older_version │ └── src │ │ └── demo │ │ ├── com │ │ └── packt │ │ │ └── CollectionsDemo.java │ │ └── module-info.java ├── 11_multirelease_jar │ ├── manifest.mf │ ├── mods9 │ │ └── com │ │ │ └── packt │ │ │ └── CollectionUtil.class │ ├── mr.jar │ ├── package.bat │ ├── package.sh │ └── src │ │ ├── 8 │ │ └── com │ │ │ └── packt │ │ │ ├── CollectionUtil.java │ │ │ └── FactoryDemo.java │ │ ├── 9 │ │ └── com │ │ │ └── packt │ │ │ └── CollectionUtil.java │ │ └── MANIFEST.MF ├── 12_services_using_maven │ ├── book-manage │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── book.manage │ │ │ ├── com │ │ │ └── packt │ │ │ │ └── manage │ │ │ │ └── BookManager.java │ │ │ └── module-info.java │ ├── book-service │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── book.service │ │ │ ├── com │ │ │ └── packt │ │ │ │ ├── model │ │ │ │ └── Book.java │ │ │ │ ├── service │ │ │ │ └── BookService.java │ │ │ │ └── spi │ │ │ │ └── BookServiceProvider.java │ │ │ └── module-info.java │ ├── mongodb-book-service │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── mongodb.book.service │ │ │ └── module-info.java │ ├── pom.xml │ ├── run-with-mongo.bat │ ├── run-with-mongo.sh │ ├── run-with-sqldb.bat │ ├── run-with-sqldb.sh │ └── sqldb-book-service │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── sqldb.book.service │ │ ├── com │ │ └── packt │ │ │ └── sqldb │ │ │ ├── SqlDbBookServiceProvider.java │ │ │ └── service │ │ │ └── SqlDbBookService.java │ │ └── module-info.java ├── 13_automatic_module │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── packt │ │ │ └── banking │ │ │ └── Banking.java │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── banking │ │ └── BankingTest.java ├── 13_automatic_module_no_maven │ ├── banking-1.0.jar │ ├── build-jar.bat │ ├── build-jar.sh │ ├── manifest.mf │ └── src │ │ └── com │ │ └── packt │ │ └── banking │ │ └── Banking.java ├── 13_using_automatic_module │ ├── run.bat │ ├── run.sh │ └── src │ │ └── banking.demo │ │ ├── com │ │ └── packt │ │ │ └── demo │ │ │ └── BankingDemo.java │ │ └── module-info.java ├── 14_open_module_for_rflxn │ ├── run.bat │ ├── run.sh │ └── src │ │ └── demo │ │ ├── com │ │ └── packt │ │ │ └── demo │ │ │ ├── OpenModuleDemo.java │ │ │ └── Person.java │ │ └── module-info.java ├── 1_json-jackson-sample │ ├── build-jar.bat │ ├── build-jar.sh │ ├── lib │ │ ├── jackson-annotations-2.9.6.jar │ │ ├── jackson-core-2.9.6.jar │ │ └── jackson-databind-2.9.6.jar │ ├── manifest.mf │ ├── run.bat │ ├── run.sh │ ├── sample.jar │ └── src │ │ └── com │ │ └── packt │ │ ├── Sample.java │ │ └── model │ │ ├── Address.java │ │ ├── Company.java │ │ ├── Geo.java │ │ └── User.java ├── 2_simple-modular-math-util │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ └── Calculator.java │ │ └── module-info.java │ ├── math.util │ │ ├── com │ │ │ └── packt │ │ │ │ └── math │ │ │ │ └── MathUtil.java │ │ └── module-info.java │ ├── run.bat │ └── run.sh ├── 3_modular_jar │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ └── Calculator.java │ │ └── module-info.java │ ├── compile-calculator.bat │ ├── compile-math.bat │ ├── compile.sh │ ├── jar-calculator.bat │ ├── jar-calculator.sh │ ├── jar-math.bat │ ├── jar-math.sh │ ├── math.util │ │ ├── com │ │ │ └── packt │ │ │ │ └── math │ │ │ │ └── MathUtil.java │ │ └── module-info.java │ ├── run.bat │ └── run.sh ├── 4_modular_jar_with_pre_java9 │ ├── calculator │ │ └── com │ │ │ └── packt │ │ │ └── calculator │ │ │ └── NonModularCalculator.java │ ├── compile-calculator.bat │ ├── compile-calculator.sh │ ├── jar-math.bat │ ├── jar-math.sh │ ├── math.util │ │ ├── com │ │ │ └── packt │ │ │ │ └── math │ │ │ │ └── MathUtil.java │ │ └── module-info.java │ ├── run.bat │ └── run.sh ├── 5_ModuleDemo │ ├── .idea │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── workspace.xml │ ├── calculator │ │ ├── calculator.iml │ │ └── src │ │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ └── Calculator.java │ │ │ └── module-info.java │ ├── math.util │ │ ├── math.util.iml │ │ └── src │ │ │ ├── com │ │ │ └── packt │ │ │ │ └── math │ │ │ │ └── MathUtil.java │ │ │ └── module-info.java │ └── out │ │ └── production │ │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ └── Calculator.class │ │ └── module-info.class │ │ └── math.util │ │ ├── com │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.class │ │ └── module-info.class ├── 6_bottom_up_migration_after │ └── src │ │ ├── banking.util │ │ ├── com │ │ │ └── packt │ │ │ │ └── banking │ │ │ │ └── BankUtil.java │ │ └── module-info.java │ │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ ├── Calculator.java │ │ │ │ └── commands │ │ │ │ ├── Command.java │ │ │ │ ├── CompoundInterestCommand.java │ │ │ │ ├── EvenCheckCommand.java │ │ │ │ ├── PrimeCheckCommand.java │ │ │ │ ├── SimpleInterestCommand.java │ │ │ │ ├── SumEvensCommand.java │ │ │ │ ├── SumOddsCommand.java │ │ │ │ └── SumPrimesCommand.java │ │ └── module-info.java │ │ └── math.util │ │ ├── com │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.java │ │ └── module-info.java ├── 6_bottom_up_migration_before │ ├── banking_util │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── banking │ │ │ └── BankUtil.java │ ├── calculator │ │ ├── lib │ │ │ ├── jackson-annotations-2.8.4.jar │ │ │ ├── jackson-core-2.8.4.jar │ │ │ └── jackson-databind-2.8.4.jar │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── calculator │ │ │ ├── Calculator.java │ │ │ └── commands │ │ │ ├── Command.java │ │ │ ├── CompoundInterestCommand.java │ │ │ ├── EvenCheckCommand.java │ │ │ ├── PrimeCheckCommand.java │ │ │ ├── SimpleInterestCommand.java │ │ │ ├── SumEvensCommand.java │ │ │ ├── SumOddsCommand.java │ │ │ └── SumPrimesCommand.java │ ├── math_util │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.java │ ├── package-banking.bat │ ├── package-banking.sh │ ├── package-calc.bat │ ├── package-calc.sh │ ├── package-math.bat │ ├── package-math.sh │ ├── run.bat │ └── run.sh ├── 7_top_down_migration_after │ ├── copy-non-mod-jar.bat │ ├── copy-non-mod-jar.sh │ └── src │ │ ├── banking.util │ │ ├── com │ │ │ └── packt │ │ │ │ └── banking │ │ │ │ └── BankUtil.java │ │ └── module-info.java │ │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ ├── Calculator.java │ │ │ │ └── commands │ │ │ │ ├── Command.java │ │ │ │ ├── CompoundInterestCommand.java │ │ │ │ ├── EvenCheckCommand.java │ │ │ │ ├── PrimeCheckCommand.java │ │ │ │ ├── SimpleInterestCommand.java │ │ │ │ ├── SumEvensCommand.java │ │ │ │ ├── SumOddsCommand.java │ │ │ │ └── SumPrimesCommand.java │ │ └── module-info.java │ │ └── math.util │ │ ├── com │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.java │ │ └── module-info.java ├── 7_top_down_migration_before │ ├── banking_util │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── banking │ │ │ └── BankUtil.java │ ├── calculator │ │ ├── lib │ │ │ ├── jackson-annotations-2.8.4.jar │ │ │ ├── jackson-core-2.8.4.jar │ │ │ └── jackson-databind-2.8.4.jar │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── calculator │ │ │ ├── Calculator.java │ │ │ └── commands │ │ │ ├── Command.java │ │ │ ├── CompoundInterestCommand.java │ │ │ ├── EvenCheckCommand.java │ │ │ ├── PrimeCheckCommand.java │ │ │ ├── SimpleInterestCommand.java │ │ │ ├── SumEvensCommand.java │ │ │ ├── SumOddsCommand.java │ │ │ └── SumPrimesCommand.java │ ├── math_util │ │ └── src │ │ │ └── com │ │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.java │ ├── package-banking.bat │ ├── package-banking.sh │ ├── package-calc.bat │ ├── package-calc.sh │ ├── package-math.bat │ ├── package-math.sh │ ├── run.bat │ └── run.sh ├── 8_services │ └── src │ │ ├── book.manage │ │ ├── com │ │ │ └── packt │ │ │ │ └── manage │ │ │ │ └── BookManager.java │ │ └── module-info.java │ │ ├── book.service │ │ ├── com │ │ │ └── packt │ │ │ │ ├── model │ │ │ │ └── Book.java │ │ │ │ ├── service │ │ │ │ └── BookService.java │ │ │ │ └── spi │ │ │ │ └── BookServiceProvider.java │ │ └── module-info.java │ │ ├── mongodb.book.service │ │ ├── com │ │ │ └── packt │ │ │ │ └── mongodb │ │ │ │ ├── MongoDbBookServiceProvider.java │ │ │ │ └── service │ │ │ │ └── MongoDbBookService.java │ │ └── module-info.java │ │ └── sqldb.book.service │ │ ├── com │ │ └── packt │ │ │ └── sqldb │ │ │ ├── SqlDbBookServiceProvider.java │ │ │ └── service │ │ │ └── SqlDbBookService.java │ │ └── module-info.java ├── 9_jlink_modular_run_time_image │ └── src │ │ ├── calculator │ │ ├── com │ │ │ └── packt │ │ │ │ └── calculator │ │ │ │ └── Calculator.java │ │ └── module-info.java │ │ └── math.util │ │ ├── com │ │ └── packt │ │ │ └── math │ │ │ └── MathUtil.java │ │ └── module-info.java ├── mvn_support_for_jigsaw │ ├── pom.xml │ ├── simple-module │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── simple.module │ │ │ ├── com │ │ │ └── packt │ │ │ │ └── SimpleModuleUsingMaven.java │ │ │ └── module-info.java │ └── simple-util │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── simple.util │ │ ├── com │ │ └── packt │ │ │ └── SimpleModularUtil.java │ │ └── module-info.java └── simple-modular-blog-proto │ └── model-module │ └── src │ └── com.packt.model │ ├── com │ └── packt │ │ └── model │ │ ├── Comment.java │ │ ├── Post.java │ │ ├── User.java │ │ └── UserPrivilege.java │ └── module-info.java ├── Chapter04 ├── a │ ├── Chapter04Functional$1.class │ ├── Chapter04Functional$10.class │ ├── Chapter04Functional$11.class │ ├── Chapter04Functional$12.class │ ├── Chapter04Functional$13.class │ ├── Chapter04Functional$14.class │ ├── Chapter04Functional$15.class │ ├── Chapter04Functional$2.class │ ├── Chapter04Functional$3.class │ ├── Chapter04Functional$4.class │ ├── Chapter04Functional$5.class │ ├── Chapter04Functional$6.class │ ├── Chapter04Functional$7.class │ ├── Chapter04Functional$8.class │ ├── Chapter04Functional$9.class │ ├── Chapter04Functional$Demo$1.class │ ├── Chapter04Functional$Demo.class │ ├── Chapter04Functional.class │ └── Chapter04Functional.java ├── b │ └── Chapter04Functional.java └── c │ ├── Chapter04Functional.java │ ├── FactorySpeedModel.java │ ├── FactoryTraffic.java │ ├── FactoryVehicle.java │ └── api │ ├── Car.java │ ├── SpeedModel.java │ ├── TrafficUnit.java │ ├── Truck.java │ └── Vehicle.java ├── Chapter05 ├── Chapter05Streams.java ├── FactorySpeedModel.java ├── FactoryTraffic.java ├── FactoryVehicle.java ├── Grouping.java ├── NumericStreams.java ├── ProduceCollection.java ├── ProduceMap.java ├── Thing.java ├── TrafficDensity1.java ├── TrafficDensity2.java ├── TrafficDensity3.java └── api │ ├── Car.java │ ├── SpeedModel.java │ ├── TrafficUnit.java │ ├── Truck.java │ └── Vehicle.java ├── Chapter06 ├── BatchProcessing.java ├── Chapter06Database01.java ├── Chapter06Database02.java ├── HikariPool.java ├── image1.png ├── jpa │ ├── Family.java │ ├── JpaHibernate.java │ ├── Person1.java │ └── Person2.java └── mybatis │ ├── Family.java │ ├── MyBatis.java │ ├── Person1.java │ └── Person2.java ├── Chapter07 ├── AverageSpeed.java ├── Chapter07Concurrency01.java ├── Chapter07Concurrency02.java ├── Chapter07Concurrency03.java ├── Chapter07Concurrency04.java ├── DemoSubscriber.java ├── DemoSubscription.java ├── FactorySpeedModel.java ├── FactoryTraffic.java ├── FactoryVehicle.java └── api │ ├── Car.java │ ├── DateLocation.java │ ├── SpeedModel.java │ ├── TrafficUnit.java │ ├── Truck.java │ └── Vehicle.java ├── Chapter08 ├── 10_connecting_process_pipe │ ├── iris.data.txt │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── PipeDemo.java │ │ └── module-info.java ├── 11_managing_sub_process │ ├── run.sh │ ├── script.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── ManageSubProcessDemo.java │ │ └── module-info.java ├── 1_spawn_new_process │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── NewProcessDemo.java │ │ └── module-info.java ├── 2_redirect_to_file │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ ├── RedirectFileDemo.java │ │ │ └── input │ │ └── module-info.java ├── 3_change_work_directory │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── ChangeWorkDirectoryDemo.java │ │ └── module-info.java ├── 4_environment_variables │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── EnvironmentVariableDemo.java │ │ └── module-info.java ├── 5_running_shell_script │ ├── run.sh │ ├── script.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── RunningShellScriptDemo.java │ │ └── module-info.java ├── 6_current_process_info │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── CurrentProcessInfoDemo.java │ │ └── module-info.java ├── 7_spawned_process_info │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── SpawnedProcessInfoDemo.java │ │ └── module-info.java ├── 8_manage_spawned_process │ ├── run.sh │ └── src │ │ └── process │ │ ├── com │ │ └── packt │ │ │ └── process │ │ │ └── ManageSpawnedProcessDemo.java │ │ └── module-info.java └── 9_enumerate_all_processes │ ├── run.sh │ └── src │ └── process │ ├── com │ └── packt │ │ └── process │ │ └── EnumerateProcessDemo.java │ └── module-info.java ├── Chapter09 ├── 1_boot_demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_demo │ │ │ │ ├── BootDemoApplication.java │ │ │ │ └── SimpleViewController.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ └── message.html │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_demo │ │ └── BootDemoApplicationTests.java ├── 2_boot_db_demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_db_demo │ │ │ │ ├── BootDbDemoApplication.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonContoller.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ ├── detail.html │ │ │ ├── form.html │ │ │ └── list.html │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_db_demo │ │ └── BootDbDemoApplicationTests.java ├── 3_boot_rest_demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_rest_demo │ │ │ │ ├── BootRestDemoApplication.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonApiController.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── mappers │ │ │ └── PersonMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_rest_demo │ │ └── BootRestDemoApplicationTests.java ├── 4_boot_db_demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_db_demo │ │ │ │ ├── BootDbDemoApplication.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonContoller.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ ├── detail.html │ │ │ ├── form.html │ │ │ └── list.html │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_db_demo │ │ └── BootDbDemoApplicationTests.java ├── 4_boot_multi_profile_complete │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_rest_demo │ │ │ │ ├── BootMultiProfileDemo.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonApiController.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application-cloud.properties │ │ │ ├── application-local.properties │ │ │ ├── application.properties │ │ │ └── mappers │ │ │ └── PersonMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_rest_demo │ │ └── BootRestDemoApplicationTests.java ├── 4_boot_multi_profile_incomplete │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_rest_demo │ │ │ │ ├── BootMultiProfileDemo.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonApiController.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── mappers │ │ │ └── PersonMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_rest_demo │ │ └── BootRestDemoApplicationTests.java ├── 5_boot_on_heroku │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── restapp │ │ │ │ ├── AppController.java │ │ │ │ ├── BootMultiProfileDemo.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonApiController.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application-cloud.properties │ │ │ ├── application-heroku.properties │ │ │ ├── application-local.properties │ │ │ ├── application.properties │ │ │ ├── mappers │ │ │ └── PersonMapper.xml │ │ │ └── templates │ │ │ └── index.html │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── restapp │ │ └── BootRestDemoApplicationTests.java ├── 6_boot_with_docker │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── Dockerfile │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── packt │ │ │ │ └── boot_rest_demo │ │ │ │ ├── BootMultiProfileDemo.java │ │ │ │ ├── Person.java │ │ │ │ ├── PersonApiController.java │ │ │ │ └── PersonMapper.java │ │ └── resources │ │ │ ├── application-cloud.properties │ │ │ ├── application-local.properties │ │ │ ├── application.properties │ │ │ └── mappers │ │ │ └── PersonMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── packt │ │ └── boot_rest_demo │ │ └── BootRestDemoApplicationTests.java └── 7_boot_micrometer │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── packt │ │ │ └── boot_db_demo │ │ │ ├── BootDbDemoApplication.java │ │ │ ├── Person.java │ │ │ ├── PersonContoller.java │ │ │ └── PersonMapper.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ ├── detail.html │ │ ├── form.html │ │ └── list.html │ └── test │ └── java │ └── com │ └── packt │ └── boot_db_demo │ └── BootDbDemoApplicationTests.java ├── Chapter10 ├── 1_making_http_get │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ └── HttpGetDemo.java │ │ └── module-info.java ├── 2_making_http_post │ ├── mods │ │ ├── jackson.annotations.jar │ │ ├── jackson.core.jar │ │ └── jackson.databind.jar │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ └── HttpPostDemo.java │ │ └── module-info.java ├── 3_making_http_request_protected_res │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ ├── HttpRequestProtectedResDemo.java │ │ │ └── UsernamePasswordAuthenticator.java │ │ └── module-info.java ├── 4_async_http_request │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ └── AsyncHttpRequestDemo.java │ │ └── module-info.java ├── 5_1_apache_http_demo_response_handler │ ├── mods │ │ ├── commons.codec.jar │ │ ├── commons.logging.jar │ │ ├── httpclient.jar │ │ └── httpcore.jar │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ └── ApacheHttpClientResponseHandlerDemo.java │ │ └── module-info.java ├── 5_apache_http_demo │ ├── mods │ │ ├── commons.codec.jar │ │ ├── commons.logging.jar │ │ ├── httpclient.jar │ │ └── httpcore.jar │ ├── run.bat │ ├── run.sh │ └── src │ │ └── http.client.demo │ │ ├── com │ │ └── packt │ │ │ └── ApacheHttpClientDemo.java │ │ └── module-info.java └── 6_unirest_http_demo │ ├── mods │ ├── commons.codec.jar │ ├── commons.logging.jar │ ├── httpasyncclient.jar │ ├── httpclient.jar │ ├── httpcore.jar │ ├── httpcore.nio.jar │ ├── httpmime.jar │ ├── json.jar │ └── unirest.java.jar │ ├── run.bat │ ├── run.sh │ └── src │ └── http.client.demo │ ├── com │ └── packt │ │ └── UnirestHttpClientDemo.java │ └── module-info.java ├── Chapter11 ├── Chapter11Memory.java ├── Epsilon.java ├── MemoryAwareStyle.java └── walk │ ├── Clazz01.java │ ├── Clazz02.java │ └── Clazz03.java ├── Chapter12 ├── 4_oo_programming │ ├── Car.java │ ├── Dimensions.java │ ├── Engine.java │ └── history └── 6_jshell_api │ ├── run.bat │ ├── run.sh │ └── src │ └── jshell │ ├── com │ └── packt │ │ └── JshellJavaApiDemo.java │ └── module-info.java ├── Chapter13 ├── 1_2_print_calendar │ ├── run.bat │ ├── run.sh │ └── src │ │ └── datedemo │ │ ├── com │ │ └── packt │ │ │ └── Main.java │ │ └── module-info.java ├── 1_create_date_time │ ├── run.bat │ ├── run.sh │ └── src │ │ └── datedemo │ │ ├── com │ │ └── packt │ │ │ └── Main.java │ │ └── module-info.java └── 2_create_tz_date_time │ ├── run.bat │ ├── run.sh │ └── src │ └── datedemo │ ├── com │ └── packt │ │ └── Main.java │ └── module-info.java ├── Chapter14 ├── AverageSpeed.java ├── Chapter14Testing.java ├── TrafficDensity.java ├── api │ ├── Car.java │ ├── SpeedModel.java │ ├── TrafficUnit.java │ ├── Truck.java │ └── Vehicle.java ├── factories │ ├── DateLocation.java │ ├── FactorySpeedModel.java │ ├── FactoryTraffic.java │ └── FactoryVehicle.java ├── process │ ├── Dispatcher.java │ ├── Process.java │ ├── Processor.java │ └── Subscription.java └── utils │ └── DbUtil.java ├── Chapter15 ├── a_var │ └── Chapter15Var.java ├── b_lambdas │ ├── Chapter15Upgrades.java │ └── Chapter15Var.java └── c_enum │ ├── Chapter15Enum.java │ ├── FactorySpeedModel.java │ ├── FactoryVehicle.java │ └── api │ ├── Car.java │ ├── SpeedModel.java │ ├── Truck.java │ └── Vehicle.java ├── Chapter16 ├── 101_student_data_processor │ ├── build-jar.bat │ ├── build-jar.sh │ └── src │ │ └── student.processor │ │ ├── com │ │ └── packt │ │ │ └── processor │ │ │ ├── ParentEducation.java │ │ │ ├── Student.java │ │ │ ├── StudentDataProcessor.java │ │ │ └── students │ │ └── module-info.java ├── 13_tiff_reader │ ├── run.bat │ ├── run.sh │ ├── sample.tif │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── BrowserDemo$1.class │ │ │ ├── BrowserDemo.class │ │ │ └── TiffReaderDemo.java │ │ └── module-info.java ├── 1_create_javafx_gui │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ └── CreateGuiDemo.java │ │ └── module-info.java ├── 2_fxml_gui │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── FxmlController.java │ │ │ ├── FxmlGuiDemo.java │ │ │ └── fxml_age_calc_gui.fxml │ │ └── module-info.java ├── 3_css_javafx │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── CssJavaFxDemo.java │ │ │ └── stylesheet.css │ │ └── module-info.java ├── 4_bar_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ └── BarChartDemo.java │ │ └── module-info.java ├── 5_2_area_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── AreaChartDemo.java │ │ │ ├── Marks.java │ │ │ ├── OilPrice.java │ │ │ ├── brent-oil │ │ │ ├── crude-oil │ │ │ └── marks │ │ └── module-info.java ├── 5_3_line_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── LineChartDemo.java │ │ │ ├── OilPrice.java │ │ │ ├── brent-oil │ │ │ └── crude-oil │ │ └── module-info.java ├── 5_4_bubble_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── BubbleChartDemo.java │ │ │ ├── StoreVisit.java │ │ │ └── store │ │ └── module-info.java ├── 5_5_scatter_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── FallOfWicket.java │ │ │ ├── ScatterChartDemo.java │ │ │ └── wickets │ │ └── module-info.java ├── 5_pie_charts │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ └── PieChartDemo.java │ │ └── module-info.java ├── 6_embed_html │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── BrowserDemo$1.class │ │ │ ├── BrowserDemo.class │ │ │ └── BrowserDemo.java │ │ └── module-info.java ├── 7_embed_audio_video │ ├── run.bat │ ├── run.sh │ ├── sample_video1.mp4 │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ └── EmbedAudioVideoDemo.java │ │ └── module-info.java ├── 8_effects_demo │ ├── run.bat │ ├── run.sh │ └── src │ │ └── gui │ │ ├── com │ │ └── packt │ │ │ ├── BrowserDemo$1.class │ │ │ ├── BrowserDemo.class │ │ │ └── EffectsDemo.java │ │ └── module-info.java └── 9_robot_api │ ├── run.bat │ ├── run.sh │ ├── screenCapture-2018-23-9-18-2-03.png │ └── src │ └── gui │ ├── com │ └── packt │ │ └── RobotAPIDemo.java │ └── module-info.java ├── LICENSE └── README.md /Chapter02/a_classes/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.a_classes; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount; 5 | 6 | public Car(int passengersCount, int weightPounds, Engine engine) { 7 | super(weightPounds, engine); 8 | this.passengersCount = passengersCount; 9 | } 10 | 11 | public int getPassengersCount() { 12 | return this.passengersCount; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Chapter02/a_classes/Chapter02Classes.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.a_classes; 2 | 3 | public class Chapter02Classes { 4 | 5 | public static void main(String... args) { 6 | double timeSec = 10.0; 7 | int engineHorsePower = 246; 8 | int vehicleWeightPounds = 4000; 9 | 10 | Engine engine = new Engine(); 11 | engine.setHorsePower(engineHorsePower); 12 | 13 | Vehicle vehicle = new Vehicle(vehicleWeightPounds, engine); 14 | System.out.println("Vehicle speed (" + timeSec + " sec) = " + vehicle.getSpeedMph(timeSec) + " mph"); 15 | 16 | vehicle = new Car(4, vehicleWeightPounds, engine); 17 | 18 | System.out.println("Car speed (" + timeSec + " sec) = " + vehicle.getSpeedMph(timeSec) + " mph"); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter02/a_classes/Engine.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.a_classes; 2 | 3 | public class Engine { 4 | private int horsePower; 5 | 6 | public int getHorsePower() { 7 | return horsePower; 8 | } 9 | 10 | public void setHorsePower(int horsePower) { 11 | this.horsePower = horsePower; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/a_classes/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.a_classes; 2 | 3 | public class Vehicle { 4 | private int weightPounds; 5 | private Engine engine; 6 | 7 | public Vehicle(int weightPounds, Engine engine) { 8 | this.weightPounds = weightPounds; 9 | if(engine == null){ 10 | throw new RuntimeException("Engine value is not set."); 11 | } 12 | this.engine = engine; 13 | } 14 | 15 | public int getWeightPounds() { 16 | return weightPounds; 17 | } 18 | 19 | public Engine getEngine() { return engine; } 20 | 21 | protected double getSpeedMph(double timeSec){ 22 | double v = 2.0*this.engine.getHorsePower()*746; 23 | v = v*timeSec*32.174/this.weightPounds; 24 | return Math.round(Math.sqrt(v)*0.68); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Chapter02/b_innerclass/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.b_innerclass; 2 | 3 | public class Vehicle { 4 | private int weightPounds; 5 | private Engine engine; 6 | 7 | public Vehicle(int weightPounds, int horsePower) { 8 | this.weightPounds = weightPounds; 9 | this.engine = new Engine(horsePower); 10 | } 11 | 12 | public double getSpeedMph(double timeSec){ 13 | double v = 2.0*this.engine.getHorsePower()*746; 14 | v = v*timeSec*32.174/this.weightPounds; 15 | return Math.round(Math.sqrt(v)*0.68); 16 | } 17 | 18 | private class Engine { 19 | private int horsePower; 20 | private Engine(int horsePower) { 21 | this.horsePower = horsePower; 22 | } 23 | public int getHorsePower() { return horsePower; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/a/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.a; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount; 5 | 6 | public Car(int passengersCount, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.passengersCount = passengersCount; 9 | } 10 | public int getPassengersCount() { 11 | return this.passengersCount; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/a/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.a; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.payload = payloadPounds; 9 | } 10 | public int getPayload() { return this.payload; } 11 | 12 | } -------------------------------------------------------------------------------- /Chapter02/c_inheritance/a/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.a; 2 | 3 | public class Vehicle { 4 | private int weightPounds, horsePower; 5 | 6 | public Vehicle(int weightPounds, int horsePower) { 7 | this.weightPounds = weightPounds; 8 | this.horsePower = horsePower; 9 | } 10 | 11 | public double getSpeedMph(double timeSec){ 12 | double v = 2.0*this.horsePower*746; 13 | v = v*timeSec*32.174/weightPounds; 14 | return Math.round(Math.sqrt(v)*0.68); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/b/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.b; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload, weightPounds, horsePower; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.payload = payloadPounds; 9 | this.weightPounds = weightPounds; 10 | this.horsePower = horsePower; 11 | } 12 | 13 | public int getPayload() { return this.payload; } 14 | 15 | public double getSpeedMph(double timeSec) { 16 | int weight = this.weightPounds + this.payload; 17 | double v = 2.0*this.horsePower*746; 18 | v = v*timeSec*32.174/weight; 19 | return Math.round(Math.sqrt(v)*0.68); 20 | } 21 | } -------------------------------------------------------------------------------- /Chapter02/c_inheritance/b/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.b; 2 | 3 | public class Vehicle { 4 | private int weightPounds, horsePower; 5 | 6 | public Vehicle(int weightPounds, int horsePower) { 7 | this.weightPounds = weightPounds; 8 | this.horsePower = horsePower; 9 | } 10 | 11 | public double getSpeedMph(double timeSec){ 12 | double v = 2.0*this.horsePower*746; 13 | v = v*timeSec*32.174/weightPounds; 14 | return Math.round(Math.sqrt(v)*0.68); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/c/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.c; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount, weightPounds; 5 | public Car(int passengersCount, int weightPounds, int horsePower) { 6 | super(weightPounds, horsePower); 7 | this.passengersCount = passengersCount; 8 | this.weightPounds = weightPounds; 9 | } 10 | public int getPassengersCount() { 11 | return this.passengersCount; 12 | } 13 | public double getSpeedMph(double timeSec) { 14 | int weight = this.weightPounds + this.passengersCount * 250; 15 | return getSpeedMph(timeSec, weight); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/c/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.c; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload, weightPounds; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.payload = payloadPounds; 9 | this.weightPounds = weightPounds; 10 | } 11 | 12 | public int getPayload() { return this.payload; } 13 | 14 | public double getSpeedMph(double timeSec) { 15 | int weight = this.weightPounds + this.payload; 16 | return getSpeedMph(timeSec, weight); 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter02/c_inheritance/c/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.c; 2 | 3 | public class Vehicle { 4 | private int weightPounds, horsePower; 5 | 6 | public Vehicle(int weightPounds, int horsePower) { 7 | this.weightPounds = weightPounds; 8 | this.horsePower = horsePower; 9 | } 10 | 11 | protected double getSpeedMph(double timeSec, int weightPounds){ 12 | double v = 2.0*this.horsePower*746; 13 | v = v*timeSec*32.174/weightPounds; 14 | return Math.round(Math.sqrt(v)*0.68); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/d/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.d; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount, weightPounds; 5 | 6 | public Car(int passengersCount, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.passengersCount = passengersCount; 9 | this.weightPounds = weightPounds; 10 | } 11 | 12 | public int getPassengersCount() { 13 | return this.passengersCount; 14 | } 15 | 16 | public int getMaxWeightPounds() { 17 | return weightPounds + passengersCount * 250; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/d/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.d; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload, weightPounds; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds, horsePower); 8 | this.payload = payloadPounds; 9 | this.weightPounds = weightPounds; 10 | } 11 | 12 | public int getPayload() { 13 | return this.payload; 14 | } 15 | 16 | public int getMaxWeightPounds() { return weightPounds + payload; } 17 | } -------------------------------------------------------------------------------- /Chapter02/c_inheritance/d/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.d; 2 | 3 | public abstract class Vehicle { 4 | private int weightPounds, horsePower; 5 | 6 | public Vehicle(int weightPounds, int horsePower) { 7 | this.weightPounds = weightPounds; 8 | this.horsePower = horsePower; 9 | } 10 | 11 | public abstract int getMaxWeightPounds(); 12 | 13 | public double getSpeedMph(double timeSec){ 14 | double v = 2.0*this.horsePower*746; 15 | v = v*timeSec*32.174/getMaxWeightPounds(); 16 | return Math.round(Math.sqrt(v)*0.68); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/e/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.e; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount; 5 | public Car(int passengersCount, int weightPounds, int horsePower) { 6 | super(weightPounds + passengersCount * 250, horsePower); 7 | this.passengersCount = passengersCount; 8 | } 9 | public int getPassengersCount() { 10 | return this.passengersCount; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter02/c_inheritance/e/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.e; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds + payloadPounds, horsePower); 8 | this.payload = payloadPounds; 9 | } 10 | 11 | public int getPayload() { return this.payload; } 12 | } -------------------------------------------------------------------------------- /Chapter02/c_inheritance/e/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.c_inheritance.e; 2 | 3 | public class Vehicle { 4 | private int weightPounds, horsePower; 5 | 6 | public Vehicle(int weightPounds, int horsePower) { 7 | this.weightPounds = weightPounds; 8 | this.horsePower = horsePower; 9 | } 10 | 11 | public double getSpeedMph(double timeSec){ 12 | double v = 2.0*this.horsePower*746; 13 | v = v*timeSec*32.174/weightPounds; 14 | return Math.round(Math.sqrt(v)*0.68); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/d_composition/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.d_composition; 2 | 3 | public class Car extends Vehicle { 4 | private int passengersCount; 5 | 6 | public Car(int passengersCount, int weightPounds, int horsePower) { 7 | super(weightPounds + passengersCount * 250, horsePower); 8 | this.passengersCount = passengersCount; 9 | } 10 | 11 | public int getPassengersCount() { 12 | return this.passengersCount; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter02/d_composition/Chapter02Composition.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.d_composition; 2 | 3 | import java.util.Properties; 4 | 5 | public class Chapter02Composition { 6 | 7 | public static void main(String arg[]) { 8 | double timeSec = 10.0; 9 | int horsePower = 246; 10 | int vehicleWeight = 4000; 11 | 12 | Properties drivingConditions = new Properties(); 13 | drivingConditions.put("roadCondition", "Wet"); 14 | drivingConditions.put("tireCondition", "New"); 15 | SpeedModel speedModel = new SpeedModel(drivingConditions); 16 | 17 | Car car = new Car(4, vehicleWeight, horsePower); 18 | car.setSpeedModel(speedModel); 19 | System.out.println("Car speed (" + timeSec + " sec) = " + car.getSpeedMph(timeSec) + " mph"); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter02/d_composition/SpeedModel.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.d_composition; 2 | 3 | import java.util.Properties; 4 | 5 | public class SpeedModel { 6 | private Properties conditions; 7 | 8 | public SpeedModel(Properties drivingConditions){ 9 | this.conditions = drivingConditions; 10 | } 11 | 12 | public double getSpeedMph(double timeSec, int weightPounds, int horsePower){ 13 | String road = conditions.getProperty("roadCondition", "Dry"); 14 | String tire = conditions.getProperty("tireCondition", "New"); 15 | double v = 2.0*horsePower*746; 16 | v = v*timeSec*32.174/weightPounds; 17 | return Math.round(Math.sqrt(v)*0.68) - (road.equals("Dry")?2:5) - (tire.equals("New")?0:5); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter02/d_composition/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.d_composition; 2 | 3 | public class Truck extends Vehicle { 4 | private int payload, weightPounds; 5 | 6 | public Truck(int payloadPounds, int weightPounds, int horsePower) { 7 | super(weightPounds + payloadPounds, horsePower); 8 | this.payload = payloadPounds; 9 | this.weightPounds = weightPounds; 10 | } 11 | 12 | public int getPayload() { 13 | return this.payload; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Chapter02/d_composition/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.d_composition; 2 | 3 | public class Vehicle { 4 | private SpeedModel speedModel; 5 | private int weightPounds, horsePower; 6 | 7 | public Vehicle(int weightPounds, int horsePower) { 8 | this.weightPounds = weightPounds; 9 | this.horsePower = horsePower; 10 | } 11 | public void setSpeedModel(SpeedModel speedModel){ 12 | this.speedModel = speedModel; 13 | } 14 | public double getSpeedMph(double timeSec){ 15 | return this.speedModel.getSpeedMph(timeSec, weightPounds, horsePower); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter02/e_interface/a/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.a.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter02/e_interface/a/api/SpeedModel.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.a.api; 2 | 3 | public interface SpeedModel { 4 | double getSpeedMph(double timeSec, int weightPounds, int horsePower); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter02/e_interface/a/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.a.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | default int getPayloadKg(){ 6 | return convertPoundsToKg(getPayloadPounds()); 7 | } 8 | 9 | default int getWeightKg(int pounds){ 10 | return convertPoundsToKg(pounds); 11 | } 12 | 13 | private int convertPoundsToKg(int pounds){ 14 | return (int) Math.round(0.454 * pounds); 15 | } 16 | 17 | static int convertKgToPounds(int kilograms){ 18 | return (int) Math.round(2.205 * kilograms); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter02/e_interface/a/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.a.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | } 7 | -------------------------------------------------------------------------------- /Chapter02/e_interface/b/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.b.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter02/e_interface/b/api/SpeedModel.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.b.api; 2 | 3 | public interface SpeedModel { 4 | double getSpeedMph(double timeSec, int weightPounds, int horsePower); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter02/e_interface/b/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.b.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | default int getPayloadKg(){ 6 | return convertPoundsToKg(getPayloadPounds()); 7 | } 8 | 9 | static int convertPoundsToKg(int pounds){ 10 | return (int) Math.round(0.454 * pounds); 11 | } 12 | 13 | static int convertKgToPounds(int kilograms){ 14 | return (int) Math.round(2.205 * kilograms); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter02/e_interface/b/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch02_oop.e_interface.b.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | } 7 | -------------------------------------------------------------------------------- /Chapter03/10_compiling_older_version/src/demo/com/packt/CollectionsDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | import java.util.Map; 3 | import java.util.HashMap; 4 | 5 | public class CollectionsDemo{ 6 | public static void main(String[] args){ 7 | Map map = new HashMap<>(); 8 | map.put("key1", "value1"); 9 | map.put("key2", "value3"); 10 | map.put("key3", "value3"); 11 | map.forEach((k,v) -> System.out.println(k + ", " + v)); 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter03/10_compiling_older_version/src/demo/module-info.java: -------------------------------------------------------------------------------- 1 | module demo{} -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/manifest.mf: -------------------------------------------------------------------------------- 1 | Multi-Release: true -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/mods9/com/packt/CollectionUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/11_multirelease_jar/mods9/com/packt/CollectionUtil.class -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/mr.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/11_multirelease_jar/mr.jar -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/package.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --release 8 src\8\com\packt\*.java 2 | javac -d mods9 --release 9 src\9\com\packt\*.java 3 | 4 | jar --create --file mr.jar --main-class=com.packt.FactoryDemo -C mods . --release 9 -C mods9 . -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/package.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --release 8 $(find src/8 -name "*.java") 2 | javac -d mods9 --release 9 $(find src/9 -name "*.java") 3 | 4 | jar --create --file mr.jar --main-class=com.packt.FactoryDemo -C mods . --release 9 -C mods9 . -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/src/8/com/packt/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | 4 | import java.util.Set; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Arrays; 8 | 9 | public class CollectionUtil{ 10 | public static List list(String ... args){ 11 | System.out.println("Using Arrays.asList"); 12 | return Arrays.asList(args); 13 | } 14 | 15 | public static Set set(String ... args){ 16 | System.out.println("Using Arrays.asList and set.addAll"); 17 | Set set = new HashSet<>(); 18 | set.addAll(list(args)); 19 | return set; 20 | } 21 | } -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/src/8/com/packt/FactoryDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | 4 | public class FactoryDemo{ 5 | public static void main(String[] args){ 6 | System.out.println(CollectionUtil.list("element1", "element2", "element3")); 7 | System.out.println(CollectionUtil.set("element1", "element2", "element3")); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/src/9/com/packt/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | import java.util.List; 6 | 7 | public class CollectionUtil{ 8 | 9 | public static List list(String ... args){ 10 | System.out.println("Using factory methods"); 11 | return List.of(args); 12 | } 13 | 14 | public static Set set(String ... args){ 15 | System.out.println("Using factory methods"); 16 | return Set.of(args); 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter03/11_multirelease_jar/src/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Multi-Release: true -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-manage/src/main/book.manage/com/packt/manage/BookManager.java: -------------------------------------------------------------------------------- 1 | package com.packt.manage; 2 | 3 | import com.packt.service.BookService; 4 | import com.packt.model.Book; 5 | 6 | public class BookManager{ 7 | public static void main(String[] args){ 8 | BookService service = BookService.getInstance(); 9 | System.out.println(service.getClass()); 10 | Book book = new Book("1", "Title", "Author"); 11 | service.create(book); 12 | service.read("1"); 13 | service.update(book); 14 | service.delete("1"); 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-manage/src/main/book.manage/module-info.java: -------------------------------------------------------------------------------- 1 | module book.manage{ 2 | requires book.service; 3 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.packt 9 | services_using_maven 10 | 1.0 11 | 12 | 13 | book-service 14 | 1.0 15 | 16 | 17 | src/main/book.service 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-service/src/main/book.service/com/packt/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class Book{ 4 | public Book(String id, String title, String author){ 5 | this.id = id; 6 | this.title = title; 7 | this.author = author; 8 | } 9 | 10 | public String id; 11 | public String title; 12 | public String author; 13 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-service/src/main/book.service/com/packt/spi/BookServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.packt.spi; 2 | 3 | import com.packt.service.BookService; 4 | 5 | public interface BookServiceProvider{ 6 | public BookService getBookService(); 7 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/book-service/src/main/book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module book.service{ 2 | exports com.packt.model; 3 | exports com.packt.service; 4 | exports com.packt.spi; 5 | uses com.packt.spi.BookServiceProvider; 6 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/mongodb-book-service/src/main/mongodb.book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module mongodb.book.service{ 2 | requires book.service; 3 | provides com.packt.spi.BookServiceProvider 4 | with com.packt.mongodb.MongoDbBookServiceProvider; 5 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/run-with-mongo.bat: -------------------------------------------------------------------------------- 1 | java -p book-manage\target\book-manage-1.0.jar;book-service\target\book-service-1.0.jar;mongodb-book-service\target\mongodb-book-service-1.0.jar -m book.manage/com.packt.manage.BookManager -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/run-with-mongo.sh: -------------------------------------------------------------------------------- 1 | java -p book-manage/target/book-manage-1.0.jar:book-service/target/book-service-1.0.jar:mongodb-book-service/target/mongodb-book-service-1.0.jar -m book.manage/com.packt.manage.BookManager -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/run-with-sqldb.bat: -------------------------------------------------------------------------------- 1 | java -p book-manage\target\book-manage-1.0.jar;book-service\target\book-service-1.0.jar;sqldb-book-service\target\sqldb-book-service-1.0.jar -m book.manage/com.packt.manage.BookManager -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/run-with-sqldb.sh: -------------------------------------------------------------------------------- 1 | java -p book-manage/target/book-manage-1.0.jar:book-service/target/book-service-1.0.jar:sqldb-book-service/target/sqldb-book-service-1.0.jar -m book.manage/com.packt.manage.BookManager -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/sqldb-book-service/src/main/sqldb.book.service/com/packt/sqldb/SqlDbBookServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.packt.sqldb; 2 | 3 | import com.packt.spi.BookServiceProvider; 4 | import com.packt.sqldb.service.SqlDbBookService; 5 | import com.packt.service.BookService; 6 | 7 | public class SqlDbBookServiceProvider implements BookServiceProvider{ 8 | 9 | @Override 10 | public BookService getBookService(){ 11 | return new SqlDbBookService(); 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/sqldb-book-service/src/main/sqldb.book.service/com/packt/sqldb/service/SqlDbBookService.java: -------------------------------------------------------------------------------- 1 | package com.packt.sqldb.service; 2 | 3 | import com.packt.service.BookService; 4 | import com.packt.model.Book; 5 | 6 | public class SqlDbBookService extends BookService{ 7 | public void create(Book book){ 8 | System.out.println("Sqldb Create book ... " + book.title); 9 | } 10 | public Book read(String id){ 11 | System.out.println("Sqldb Reading book ... " + id); 12 | return new Book(id, "Title", "Author"); 13 | } 14 | public void update(Book book){ 15 | System.out.println("Sqldb Updating book ... " + book.title); 16 | } 17 | public void delete(String id){ 18 | System.out.println("Sqldb Deleting ... " + id); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter03/12_services_using_maven/sqldb-book-service/src/main/sqldb.book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module sqldb.book.service{ 2 | requires book.service; 3 | provides com.packt.spi.BookServiceProvider 4 | with com.packt.sqldb.SqlDbBookServiceProvider; 5 | } -------------------------------------------------------------------------------- /Chapter03/13_automatic_module/src/main/java/com/packt/banking/Banking.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * Hello world! 7 | * 8 | */ 9 | public class Banking 10 | { 11 | public static Double simpleInterest(Double principal, 12 | Double rateOfInterest, Integer years){ 13 | Objects.requireNonNull(principal, "Principal cannot be null"); 14 | Objects.requireNonNull(rateOfInterest, "Rate of interest cannot be null"); 15 | Objects.requireNonNull(years, "Years cannot be null"); 16 | 17 | return ( principal * rateOfInterest * years ) / 100; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter03/13_automatic_module/src/test/java/com/packt/banking/BankingTest.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | 3 | import org.junit.Test; 4 | import static org.assertj.core.api.Assertions.*; 5 | 6 | /** 7 | * Unit test for simple App. 8 | */ 9 | public class BankingTest 10 | { 11 | @Test public void test_simpleInterest() 12 | { 13 | Double simpleInterest = Banking.simpleInterest(1000.0, 10.0, 2); 14 | assertThat(simpleInterest).isEqualTo(200.0); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter03/13_automatic_module_no_maven/banking-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/13_automatic_module_no_maven/banking-1.0.jar -------------------------------------------------------------------------------- /Chapter03/13_automatic_module_no_maven/build-jar.bat: -------------------------------------------------------------------------------- 1 | javac -d classes src/com/packt/banking/*.java 2 | jar cvfm banking-1.0.jar manifest.mf -C classes . 3 | -------------------------------------------------------------------------------- /Chapter03/13_automatic_module_no_maven/build-jar.sh: -------------------------------------------------------------------------------- 1 | javac -d classes -sourcepath src $(find src -name *.java) 2 | jar cvfm banking-1.0.jar manifest.mf -C classes . 3 | -------------------------------------------------------------------------------- /Chapter03/13_automatic_module_no_maven/manifest.mf: -------------------------------------------------------------------------------- 1 | Automatic-Module-Name: com.packt.banking 2 | -------------------------------------------------------------------------------- /Chapter03/13_automatic_module_no_maven/src/com/packt/banking/Banking.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * Hello world! 7 | * 8 | */ 9 | public class Banking 10 | { 11 | public static Double simpleInterest(Double principal, 12 | Double rateOfInterest, Integer years){ 13 | Objects.requireNonNull(principal, "Principal cannot be null"); 14 | Objects.requireNonNull(rateOfInterest, "Rate of interest cannot be null"); 15 | Objects.requireNonNull(years, "Years cannot be null"); 16 | 17 | return ( principal * rateOfInterest * years ) / 100; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter03/13_using_automatic_module/run.bat: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src src\banking.demo\*.java src\banking.demo\com\packt\demo\*.java 2 | java --module-path mods -m banking.demo/com.packt.demo.BankingDemo -------------------------------------------------------------------------------- /Chapter03/13_using_automatic_module/run.sh: -------------------------------------------------------------------------------- 1 | javac -p mods -d mods --module-source-path src $(find . -name "*.java") 2 | java --module-path mods -m banking.demo/com.packt.demo.BankingDemo -------------------------------------------------------------------------------- /Chapter03/13_using_automatic_module/src/banking.demo/com/packt/demo/BankingDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.demo; 2 | 3 | import com.packt.banking.Banking; 4 | 5 | public class BankingDemo{ 6 | public static void main(String[] args) { 7 | Double principal = 1000.0; 8 | Double rateOfInterest = 10.0; 9 | Integer years = 2; 10 | Double simpleInterest = Banking.simpleInterest(principal, 11 | rateOfInterest, years); 12 | System.out.println("The simple interest is: " + simpleInterest); 13 | } 14 | } -------------------------------------------------------------------------------- /Chapter03/13_using_automatic_module/src/banking.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module banking.demo{ 2 | requires com.packt.banking; 3 | } -------------------------------------------------------------------------------- /Chapter03/14_open_module_for_rflxn/run.bat: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src src\demo\*.java src\demo\com\packt\demo\*.java 2 | java --module-path mods -m demo/com.packt.demo.OpenModuleDemo -------------------------------------------------------------------------------- /Chapter03/14_open_module_for_rflxn/run.sh: -------------------------------------------------------------------------------- 1 | javac -p mods -d mods --module-source-path src $(find . -name "*.java") 2 | java --module-path mods -m demo/com.packt.demo.OpenModuleDemo -------------------------------------------------------------------------------- /Chapter03/14_open_module_for_rflxn/src/demo/com/packt/demo/Person.java: -------------------------------------------------------------------------------- 1 | package com.packt.demo; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class Person{ 6 | public Person(String firstName, String lastName, 7 | LocalDate dob, String placeOfBirth){ 8 | this.firstName = firstName; 9 | this.lastName = lastName; 10 | this.dob = dob; 11 | this.placeOfBirth = placeOfBirth; 12 | } 13 | public final String firstName; 14 | public final String lastName; 15 | public final LocalDate dob; 16 | public final String placeOfBirth; 17 | } -------------------------------------------------------------------------------- /Chapter03/14_open_module_for_rflxn/src/demo/module-info.java: -------------------------------------------------------------------------------- 1 | module demo{ 2 | requires com.fasterxml.jackson.annotation; 3 | requires com.fasterxml.jackson.core; 4 | requires com.fasterxml.jackson.databind; 5 | requires com.fasterxml.jackson.datatype.jsr310; 6 | opens com.packt.demo; 7 | } -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/build-jar.bat: -------------------------------------------------------------------------------- 1 | "%JAVA8_HOME%"\bin\javac -cp lib\*;classes -d classes src\com\packt\*.java src\com\packt\model\*.java 2 | jar cvfm sample.jar manifest.mf -C classes . 3 | -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/build-jar.sh: -------------------------------------------------------------------------------- 1 | "$JAVA8_HOME"/bin/javac -cp 'lib/*' -d classes -sourcepath src $(find src -name *.java) 2 | jar cvfm sample.jar manifest.mf -C classes . -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/lib/jackson-annotations-2.9.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/1_json-jackson-sample/lib/jackson-annotations-2.9.6.jar -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/lib/jackson-core-2.9.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/1_json-jackson-sample/lib/jackson-core-2.9.6.jar -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/lib/jackson-databind-2.9.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/1_json-jackson-sample/lib/jackson-databind-2.9.6.jar -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/manifest.mf: -------------------------------------------------------------------------------- 1 | Main-Class: com.packt.Sample 2 | Class-Path: lib/jackson-annotations-2.9.6.jar lib/jackson-core-2.9.6.jar lib/jackson-databind-2.9.6.jar 3 | -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | "%JAVA8_HOME%"\bin\javac -version 3 | rmdir /q /s classes 4 | mkdir classes 5 | "%JAVA8_HOME%"\bin\javac -cp lib\*;classes -d classes src\com\packt\*.java src\com\packt\model\*.java 6 | 7 | if %errorlevel% == 1 goto failedCompilation 8 | 9 | :runCode 10 | jar cvfm sample.jar manifest.mf -C classes . 11 | "%JAVA8_HOME%"\bin\java -jar sample.jar 12 | goto end 13 | 14 | :failedCompilation 15 | echo 'Compilation failed' 16 | 17 | :end 18 | echo 'Bye!!' -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/run.sh: -------------------------------------------------------------------------------- 1 | "$JAVA8_HOME"/bin/javac -cp 'lib/*' -d classes -sourcepath src $(find src -name *.java) 2 | jar cvfm sample.jar manifest.mf -C classes . 3 | "$JAVA8_HOME"/bin/java -jar sample.jar -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/sample.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/1_json-jackson-sample/sample.jar -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/src/com/packt/Sample.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.List; 5 | import com.packt.model.User; 6 | import java.net.URL; 7 | import com.fasterxml.jackson.core.type.TypeReference; 8 | import sun.reflect.Reflection; 9 | 10 | public class Sample{ 11 | public static void main (String [] args){ 12 | try{ 13 | System.out.println("Class: " + Reflection.getCallerClass(1).getName()); 14 | ObjectMapper mapper = new ObjectMapper(); 15 | List users = mapper.readValue(new URL("http://jsonplaceholder.typicode.com/users"), 16 | new TypeReference>(){}); 17 | users.stream().forEach(System.out::println); 18 | }catch(Exception ex){ 19 | ex.printStackTrace(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/src/com/packt/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class Address{ 4 | public String street; 5 | public String suite; 6 | public String city; 7 | public String zipcode; 8 | public Geo geo; 9 | } -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/src/com/packt/model/Company.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class Company{ 4 | public String name; 5 | public String catchPhrase; 6 | public String bs; 7 | } -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/src/com/packt/model/Geo.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class Geo{ 4 | public String lat; 5 | public String lng; 6 | } -------------------------------------------------------------------------------- /Chapter03/1_json-jackson-sample/src/com/packt/model/User.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class User{ 4 | public Integer id; 5 | public String name; 6 | public String username; 7 | public String email; 8 | public Address address; 9 | public String phone; 10 | public String website; 11 | public Company company; 12 | 13 | @Override 14 | public String toString(){ 15 | return "Name: " + this.name + ", Company: " + this.company.name; 16 | } 17 | } -------------------------------------------------------------------------------- /Chapter03/2_simple-modular-math-util/calculator/module-info.java: -------------------------------------------------------------------------------- 1 | module calculator{ 2 | requires math.util; 3 | } -------------------------------------------------------------------------------- /Chapter03/2_simple-modular-math-util/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/2_simple-modular-math-util/run.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . math.util\*.java math.util\com\packt\math\*.java calculator\*.java calculator\com\packt\calculator\*.java 2 | java --module-path mods -m calculator/com.packt.calculator.Calculator -------------------------------------------------------------------------------- /Chapter03/2_simple-modular-math-util/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . $(find . -name "*.java") 2 | java --module-path mods -m calculator/com.packt.calculator.Calculator -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/calculator/module-info.java: -------------------------------------------------------------------------------- 1 | module calculator{ 2 | requires math.util; 3 | } -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/compile-calculator.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . calculator\*.java calculator\com\packt\calculator\*.java -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/compile-math.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . math.util\*.java math.util\com\packt\math\*.java -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/compile.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . $(find . -name *.java) 2 | -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/jar-calculator.bat: -------------------------------------------------------------------------------- 1 | jar --create --file=mlib/calculator@1.0.jar --module-version 1.0 --main-class com.packt.calculator.Calculator -C mods/calculator . -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/jar-calculator.sh: -------------------------------------------------------------------------------- 1 | mkdir -p mlib 2 | jar --create --file=mlib/calculator@1.0.jar --module-version 1.0 --main-class com.packt.calculator.Calculator -C mods/calculator . 3 | -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/jar-math.bat: -------------------------------------------------------------------------------- 1 | jar --create --file=mlib/math.util@1.0.jar --module-version 1.0 -C mods/math.util . -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/jar-math.sh: -------------------------------------------------------------------------------- 1 | mkdir -p mlib 2 | jar --create --file=mlib/math.util@1.0.jar --module-version 1.0 -C mods/math.util . 3 | -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/run.bat: -------------------------------------------------------------------------------- 1 | java -p mlib -m calculator -------------------------------------------------------------------------------- /Chapter03/3_modular_jar/run.sh: -------------------------------------------------------------------------------- 1 | java -p mlib -m calculator -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/compile-calculator.bat: -------------------------------------------------------------------------------- 1 | javac --class-path mlib/* -d classes/ calculator/com/packt/calculator/*.java -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/compile-calculator.sh: -------------------------------------------------------------------------------- 1 | javac --class-path mlib/* -d classes/ --source-path calculator $(find calculator -name *.java) -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/jar-math.bat: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path . math.util\*.java math.util\com\packt\math\*.java 2 | mkdir mlib 3 | jar --create --file=mlib/math.util@1.0.jar --module-version 1.0 -C mods/math.util . -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/jar-math.sh: -------------------------------------------------------------------------------- 1 | javac -d classes --module-source-path . $(find math.util -name *.java) 2 | mkdir mlib 3 | jar --create --file mlib/math.util.jar -C classes/math.util . -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/run.bat: -------------------------------------------------------------------------------- 1 | java -cp classes;mlib/* com.packt.calculator.NonModularCalculator -------------------------------------------------------------------------------- /Chapter03/4_modular_jar_with_pre_java9/run.sh: -------------------------------------------------------------------------------- 1 | java -cp classes:mlib/* com.packt.calculator.NonModularCalculator -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/calculator/calculator.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/calculator/src/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by sanaulla on 12/6/2016. 3 | */ 4 | module calculator { 5 | requires math.util; 6 | } -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/math.util/math.util.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/math.util/src/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by sanaulla on 12/6/2016. 3 | */ 4 | module math.util { 5 | exports com.packt.math; 6 | } -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/out/production/calculator/com/packt/calculator/Calculator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/5_ModuleDemo/out/production/calculator/com/packt/calculator/Calculator.class -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/out/production/calculator/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/5_ModuleDemo/out/production/calculator/module-info.class -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/out/production/math.util/com/packt/math/MathUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/5_ModuleDemo/out/production/math.util/com/packt/math/MathUtil.class -------------------------------------------------------------------------------- /Chapter03/5_ModuleDemo/out/production/math.util/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/5_ModuleDemo/out/production/math.util/module-info.class -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/banking.util/com/packt/banking/BankUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | import java.util.stream.IntStream; 3 | import java.util.function.IntPredicate; 4 | 5 | public class BankUtil{ 6 | 7 | public static Double computeSimpleInterest(Double principal, Integer rate, Integer duration){ 8 | return (principal * rate * duration) / 100; 9 | } 10 | 11 | public static Double computeCompoundInterest(Double principal, Integer rateInPercent, 12 | Integer noOfCompoundsPerYear, Integer duration){ 13 | Double rate = rateInPercent / 100d; 14 | 15 | Double intermediate = 1 + (rate/noOfCompoundsPerYear); 16 | Double amount = principal * Math.pow(intermediate, (duration * noOfCompoundsPerYear)); 17 | return (amount - principal); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/banking.util/module-info.java: -------------------------------------------------------------------------------- 1 | module banking.util{ 2 | exports com.packt.banking; 3 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/Command.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.Map; 5 | 6 | public interface Command{ 7 | ObjectMapper objectMapper = new ObjectMapper(); 8 | public void execute() throws Exception; 9 | 10 | default void printInJson(Map data) throws Exception{ 11 | System.out.println(objectMapper.writeValueAsString(data)); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/EvenCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class EvenCheckCommand implements Command{ 7 | public final Integer number; 8 | public EvenCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isEven(number)){ 15 | printInJson(Map.of(number.toString(), "even")); 16 | //System.out.println("The number " + number +" is even"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "odd")); 19 | //System.out.println("The number " + number +" is odd"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/PrimeCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class PrimeCheckCommand implements Command{ 7 | public final Integer number; 8 | public PrimeCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isPrime(number)){ 15 | printInJson(Map.of(number.toString(), "prime")); 16 | //System.out.println("The number " + number +" is prime"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "not prime")); 19 | //System.out.println("The number " + number +" is not prime"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/SumEvensCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumEvensCommand implements Command{ 7 | public final Integer count; 8 | public SumEvensCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d evens", count) , 15 | MathUtil.sumOfFirstNEvens(count))); 16 | //System.out.println(String.format("Sum of %d evens is %d", 17 | // count, MathUtil.sumOfFirstNEvens(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/SumOddsCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumOddsCommand implements Command{ 7 | public final Integer count; 8 | public SumOddsCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d odds", count) , 15 | MathUtil.sumOfFirstNOdds(count))); 16 | // System.out.println(String.format("Sum of %d odds is %d", 17 | // count, MathUtil.sumOfFirstNOdds(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/com/packt/calculator/commands/SumPrimesCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumPrimesCommand implements Command{ 7 | public final Integer count; 8 | public SumPrimesCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d primes", count) , 15 | MathUtil.sumOfFirstNPrimes(count))); 16 | /*System.out.println(String.format("Sum of %d primes is %d", 17 | count, MathUtil.sumOfFirstNPrimes(count)));*/ 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/calculator/module-info.java: -------------------------------------------------------------------------------- 1 | module calculator{ 2 | requires math.util; 3 | requires banking.util; 4 | requires jackson.databind; 5 | requires jackson.core; 6 | requires jackson.annotations; 7 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_after/src/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/banking_util/src/com/packt/banking/BankUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | import java.util.stream.IntStream; 3 | import java.util.function.IntPredicate; 4 | 5 | public class BankUtil{ 6 | 7 | public static Double computeSimpleInterest(Double principal, Integer rate, Integer duration){ 8 | return (principal * rate * duration) / 100; 9 | } 10 | 11 | public static Double computeCompoundInterest(Double principal, Integer rateInPercent, 12 | Integer noOfCompoundsPerYear, Integer duration){ 13 | Double rate = rateInPercent / 100d; 14 | 15 | Double intermediate = 1 + (rate/noOfCompoundsPerYear); 16 | Double amount = principal * Math.pow(intermediate, (duration * noOfCompoundsPerYear)); 17 | return (amount - principal); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-annotations-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-annotations-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-core-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-core-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-databind-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/6_bottom_up_migration_before/calculator/lib/jackson-databind-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/Command.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.Map; 5 | 6 | public interface Command{ 7 | ObjectMapper objectMapper = new ObjectMapper(); 8 | public void execute() throws Exception; 9 | 10 | default void printInJson(Map data) throws Exception{ 11 | System.out.println(objectMapper.writeValueAsString(data)); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/EvenCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class EvenCheckCommand implements Command{ 7 | public final Integer number; 8 | public EvenCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isEven(number)){ 15 | printInJson(Map.of(number.toString(), "even")); 16 | //System.out.println("The number " + number +" is even"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "odd")); 19 | //System.out.println("The number " + number +" is odd"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/PrimeCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class PrimeCheckCommand implements Command{ 7 | public final Integer number; 8 | public PrimeCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isPrime(number)){ 15 | printInJson(Map.of(number.toString(), "prime")); 16 | //System.out.println("The number " + number +" is prime"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "not prime")); 19 | //System.out.println("The number " + number +" is not prime"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/SumEvensCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumEvensCommand implements Command{ 7 | public final Integer count; 8 | public SumEvensCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d evens", count) , 15 | MathUtil.sumOfFirstNEvens(count))); 16 | //System.out.println(String.format("Sum of %d evens is %d", 17 | // count, MathUtil.sumOfFirstNEvens(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/SumOddsCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumOddsCommand implements Command{ 7 | public final Integer count; 8 | public SumOddsCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d odds", count) , 15 | MathUtil.sumOfFirstNOdds(count))); 16 | // System.out.println(String.format("Sum of %d odds is %d", 17 | // count, MathUtil.sumOfFirstNOdds(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/calculator/src/com/packt/calculator/commands/SumPrimesCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumPrimesCommand implements Command{ 7 | public final Integer count; 8 | public SumPrimesCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d primes", count) , 15 | MathUtil.sumOfFirstNPrimes(count))); 16 | /*System.out.println(String.format("Sum of %d primes is %d", 17 | count, MathUtil.sumOfFirstNPrimes(count)));*/ 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-banking.bat: -------------------------------------------------------------------------------- 1 | javac -d banking_util/out/classes/ banking_util/src/com/packt/banking/*.java 2 | jar --create --file=banking_util/out/banking.util.jar -C banking_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-banking.sh: -------------------------------------------------------------------------------- 1 | javac -d banking_util/out/classes/ -sourcepath banking_util/src $(find banking_util/src -name *.java) 2 | jar --create --file=banking_util/out/banking.util.jar -C banking_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-calc.bat: -------------------------------------------------------------------------------- 1 | javac -cp calculator/lib/*;math_util/out/math.util.jar;banking_util/out/banking.util.jar -d calculator/out/classes/ calculator/src/com/packt/calculator/commands/*.java calculator/src/com/packt/calculator/*.java 2 | jar --create --file=calculator/out/calculator.jar -C calculator/out/classes/ . -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-calc.sh: -------------------------------------------------------------------------------- 1 | javac -cp calculator/lib/*:math_util/out/math.util.jar:banking_util/out/banking.util.jar -d calculator/out/classes/ -sourcepath calculator/src $(find calculator/src -name *.java) 2 | jar --create --file=calculator/out/calculator.jar -C calculator/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-math.bat: -------------------------------------------------------------------------------- 1 | javac -d math_util/out/classes/ math_util/src/com/packt/math/*.java 2 | jar --create --file=math_util/out/math.util.jar -C math_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/package-math.sh: -------------------------------------------------------------------------------- 1 | javac -d math_util/out/classes/ -sourcepath math_util/src $(find math_util/src -name *.java) 2 | jar --create --file=math_util/out/math.util.jar -C math_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/run.bat: -------------------------------------------------------------------------------- 1 | java -cp calculator/out/classes;calculator/lib/*;math_util/out/math.util.jar;banking_util/out/banking.util.jar com.packt.calculator.Calculator 2 | -------------------------------------------------------------------------------- /Chapter03/6_bottom_up_migration_before/run.sh: -------------------------------------------------------------------------------- 1 | java -cp calculator/out/classes:calculator/lib/*:math_util/out/math.util.jar:banking_util/out/banking.util.jar com.packt.calculator.Calculator 2 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/copy-non-mod-jar.bat: -------------------------------------------------------------------------------- 1 | cp ../7_top_down_migration_before/calculator/lib/jackson-annotations-2.8.4.jar mlib/jackson.annotations.jar 2 | 3 | cp ../7_top_down_migration_before/calculator/lib/jackson-core-2.8.4.jar mlib/jackson.core.jar 4 | 5 | cp ../7_top_down_migration_before/calculator/lib/jackson-databind-2.8.4.jar mlib/jackson.databind.jar 6 | 7 | cp ../7_top_down_migration_before/banking_util/out/banking.util.jar mlib/ 8 | 9 | cp ../7_top_down_migration_before/math_util/out/math.util.jar mlib/ -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/copy-non-mod-jar.sh: -------------------------------------------------------------------------------- 1 | cp ../7_top_down_migration_before/calculator/lib/jackson-annotations-2.8.4.jar mlib/jackson.annotations.jar 2 | 3 | cp ../7_top_down_migration_before/calculator/lib/jackson-core-2.8.4.jar mlib/jackson.core.jar 4 | 5 | cp ../7_top_down_migration_before/calculator/lib/jackson-databind-2.8.4.jar mlib/jackson.databind.jar 6 | 7 | cp ../7_top_down_migration_before/banking_util/out/banking.util.jar mlib/ 8 | 9 | cp ../7_top_down_migration_before/math_util/out/math.util.jar mlib/ -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/banking.util/com/packt/banking/BankUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | import java.util.stream.IntStream; 3 | import java.util.function.IntPredicate; 4 | 5 | public class BankUtil{ 6 | 7 | public static Double computeSimpleInterest(Double principal, Integer rate, Integer duration){ 8 | return (principal * rate * duration) / 100; 9 | } 10 | 11 | public static Double computeCompoundInterest(Double principal, Integer rateInPercent, 12 | Integer noOfCompoundsPerYear, Integer duration){ 13 | Double rate = rateInPercent / 100d; 14 | 15 | Double intermediate = 1 + (rate/noOfCompoundsPerYear); 16 | Double amount = principal * Math.pow(intermediate, (duration * noOfCompoundsPerYear)); 17 | return (amount - principal); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/banking.util/module-info.java: -------------------------------------------------------------------------------- 1 | module banking.util{ 2 | exports com.packt.banking; 3 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/Command.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.Map; 5 | 6 | public interface Command{ 7 | ObjectMapper objectMapper = new ObjectMapper(); 8 | public void execute() throws Exception; 9 | 10 | default void printInJson(Map data) throws Exception{ 11 | System.out.println(objectMapper.writeValueAsString(data)); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/EvenCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class EvenCheckCommand implements Command{ 7 | public final Integer number; 8 | public EvenCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isEven(number)){ 15 | printInJson(Map.of(number.toString(), "even")); 16 | //System.out.println("The number " + number +" is even"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "odd")); 19 | //System.out.println("The number " + number +" is odd"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/PrimeCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class PrimeCheckCommand implements Command{ 7 | public final Integer number; 8 | public PrimeCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isPrime(number)){ 15 | printInJson(Map.of(number.toString(), "prime")); 16 | //System.out.println("The number " + number +" is prime"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "not prime")); 19 | //System.out.println("The number " + number +" is not prime"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/SumEvensCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumEvensCommand implements Command{ 7 | public final Integer count; 8 | public SumEvensCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d evens", count) , 15 | MathUtil.sumOfFirstNEvens(count))); 16 | //System.out.println(String.format("Sum of %d evens is %d", 17 | // count, MathUtil.sumOfFirstNEvens(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/SumOddsCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumOddsCommand implements Command{ 7 | public final Integer count; 8 | public SumOddsCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d odds", count) , 15 | MathUtil.sumOfFirstNOdds(count))); 16 | // System.out.println(String.format("Sum of %d odds is %d", 17 | // count, MathUtil.sumOfFirstNOdds(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/com/packt/calculator/commands/SumPrimesCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumPrimesCommand implements Command{ 7 | public final Integer count; 8 | public SumPrimesCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d primes", count) , 15 | MathUtil.sumOfFirstNPrimes(count))); 16 | /*System.out.println(String.format("Sum of %d primes is %d", 17 | count, MathUtil.sumOfFirstNPrimes(count)));*/ 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/calculator/module-info.java: -------------------------------------------------------------------------------- 1 | module calculator{ 2 | requires math.util; 3 | requires banking.util; 4 | requires jackson.databind; 5 | requires jackson.core; 6 | requires jackson.annotations; 7 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_after/src/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/banking_util/src/com/packt/banking/BankUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.banking; 2 | import java.util.stream.IntStream; 3 | import java.util.function.IntPredicate; 4 | 5 | public class BankUtil{ 6 | 7 | public static Double computeSimpleInterest(Double principal, Integer rate, Integer duration){ 8 | return (principal * rate * duration) / 100; 9 | } 10 | 11 | public static Double computeCompoundInterest(Double principal, Integer rateInPercent, 12 | Integer noOfCompoundsPerYear, Integer duration){ 13 | Double rate = rateInPercent / 100d; 14 | 15 | Double intermediate = 1 + (rate/noOfCompoundsPerYear); 16 | Double amount = principal * Math.pow(intermediate, (duration * noOfCompoundsPerYear)); 17 | return (amount - principal); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/lib/jackson-annotations-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/7_top_down_migration_before/calculator/lib/jackson-annotations-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/lib/jackson-core-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/7_top_down_migration_before/calculator/lib/jackson-core-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/lib/jackson-databind-2.8.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter03/7_top_down_migration_before/calculator/lib/jackson-databind-2.8.4.jar -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/Command.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.Map; 5 | 6 | public interface Command{ 7 | ObjectMapper objectMapper = new ObjectMapper(); 8 | public void execute() throws Exception; 9 | 10 | default void printInJson(Map data) throws Exception{ 11 | System.out.println(objectMapper.writeValueAsString(data)); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/EvenCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class EvenCheckCommand implements Command{ 7 | public final Integer number; 8 | public EvenCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isEven(number)){ 15 | printInJson(Map.of(number.toString(), "even")); 16 | //System.out.println("The number " + number +" is even"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "odd")); 19 | //System.out.println("The number " + number +" is odd"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/PrimeCheckCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class PrimeCheckCommand implements Command{ 7 | public final Integer number; 8 | public PrimeCheckCommand(Integer n){ 9 | number = n; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | if (MathUtil.isPrime(number)){ 15 | printInJson(Map.of(number.toString(), "prime")); 16 | //System.out.println("The number " + number +" is prime"); 17 | }else{ 18 | printInJson(Map.of(number.toString(), "not prime")); 19 | //System.out.println("The number " + number +" is not prime"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/SumEvensCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumEvensCommand implements Command{ 7 | public final Integer count; 8 | public SumEvensCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d evens", count) , 15 | MathUtil.sumOfFirstNEvens(count))); 16 | //System.out.println(String.format("Sum of %d evens is %d", 17 | // count, MathUtil.sumOfFirstNEvens(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/SumOddsCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumOddsCommand implements Command{ 7 | public final Integer count; 8 | public SumOddsCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d odds", count) , 15 | MathUtil.sumOfFirstNOdds(count))); 16 | // System.out.println(String.format("Sum of %d odds is %d", 17 | // count, MathUtil.sumOfFirstNOdds(count))); 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/calculator/src/com/packt/calculator/commands/SumPrimesCommand.java: -------------------------------------------------------------------------------- 1 | package com.packt.calculator.commands; 2 | 3 | import com.packt.math.MathUtil; 4 | import java.util.Map; 5 | 6 | public class SumPrimesCommand implements Command{ 7 | public final Integer count; 8 | public SumPrimesCommand(Integer count){ 9 | this.count = count; 10 | } 11 | 12 | @Override 13 | public void execute() throws Exception{ 14 | printInJson(Map.of(String.format("Sum of %d primes", count) , 15 | MathUtil.sumOfFirstNPrimes(count))); 16 | /*System.out.println(String.format("Sum of %d primes is %d", 17 | count, MathUtil.sumOfFirstNPrimes(count)));*/ 18 | } 19 | } -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-banking.bat: -------------------------------------------------------------------------------- 1 | javac -d banking_util/out/classes/ banking_util/src/com/packt/banking/*.java 2 | jar --create --file=banking_util/out/banking.util.jar -C banking_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-banking.sh: -------------------------------------------------------------------------------- 1 | javac -d banking_util/out/classes/ -sourcepath banking_util/src $(find banking_util/src -name *.java) 2 | jar --create --file=banking_util/out/banking.util.jar -C banking_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-calc.bat: -------------------------------------------------------------------------------- 1 | javac -cp calculator/lib/*;math_util/out/math.util.jar;banking_util/out/banking.util.jar -d calculator/out/classes/ calculator/src/com/packt/calculator/commands/*.java calculator/src/com/packt/calculator/*.java 2 | jar --create --file=calculator/out/calculator.jar -C calculator/out/classes/ . -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-calc.sh: -------------------------------------------------------------------------------- 1 | javac -cp calculator/lib/*:math_util/out/math.util.jar:banking_util/out/banking.util.jar -d calculator/out/classes/ -sourcepath calculator/src $(find calculator/src -name *.java) 2 | jar --create --file=calculator/out/calculator.jar -C calculator/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-math.bat: -------------------------------------------------------------------------------- 1 | javac -d math_util/out/classes/ math_util/src/com/packt/math/*.java 2 | jar --create --file=math_util/out/math.util.jar -C math_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/package-math.sh: -------------------------------------------------------------------------------- 1 | javac -d math_util/out/classes/ -sourcepath math_util/src $(find math_util/src -name *.java) 2 | jar --create --file=math_util/out/math.util.jar -C math_util/out/classes/ . 3 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/run.bat: -------------------------------------------------------------------------------- 1 | java -cp calculator/out/classes;calculator/lib/*;math_util/out/math.util.jar;banking_util/out/banking.util.jar com.packt.calculator.Calculator 2 | -------------------------------------------------------------------------------- /Chapter03/7_top_down_migration_before/run.sh: -------------------------------------------------------------------------------- 1 | java -cp calculator/out/classes:calculator/lib/*:math_util/out/math.util.jar:banking_util/out/banking.util.jar com.packt.calculator.Calculator 2 | -------------------------------------------------------------------------------- /Chapter03/8_services/src/book.manage/com/packt/manage/BookManager.java: -------------------------------------------------------------------------------- 1 | package com.packt.manage; 2 | 3 | import com.packt.service.BookService; 4 | import com.packt.model.Book; 5 | 6 | public class BookManager{ 7 | public static void main(String[] args){ 8 | BookService service = BookService.getInstance(); 9 | System.out.println(service.getClass()); 10 | Book book = new Book("1", "Title", "Author"); 11 | service.create(book); 12 | service.read("1"); 13 | service.update(book); 14 | service.delete("1"); 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/book.manage/module-info.java: -------------------------------------------------------------------------------- 1 | module book.manage{ 2 | requires book.service; 3 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/book.service/com/packt/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public class Book{ 4 | public Book(String id, String title, String author){ 5 | this.id = id; 6 | this.title = title; 7 | this.author = author; 8 | } 9 | 10 | public String id; 11 | public String title; 12 | public String author; 13 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/book.service/com/packt/spi/BookServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.packt.spi; 2 | 3 | import com.packt.service.BookService; 4 | 5 | public interface BookServiceProvider{ 6 | public BookService getBookService(); 7 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module book.service{ 2 | exports com.packt.model; 3 | exports com.packt.service; 4 | exports com.packt.spi; 5 | uses com.packt.spi.BookServiceProvider; 6 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/mongodb.book.service/com/packt/mongodb/MongoDbBookServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.packt.mongodb; 2 | 3 | import com.packt.spi.BookServiceProvider; 4 | import com.packt.mongodb.service.MongoDbBookService; 5 | import com.packt.service.BookService; 6 | 7 | public class MongoDbBookServiceProvider implements BookServiceProvider{ 8 | 9 | @Override 10 | public BookService getBookService(){ 11 | return new MongoDbBookService(); 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/mongodb.book.service/com/packt/mongodb/service/MongoDbBookService.java: -------------------------------------------------------------------------------- 1 | package com.packt.mongodb.service; 2 | 3 | import com.packt.service.BookService; 4 | import com.packt.model.Book; 5 | 6 | public class MongoDbBookService extends BookService{ 7 | public void create(Book book){ 8 | System.out.println("Mongodb Create book ... " + book.title); 9 | } 10 | public Book read(String id){ 11 | System.out.println("Mongodb Reading book ... " + id); 12 | return new Book(id, "Title", "Author"); 13 | } 14 | public void update(Book book){ 15 | System.out.println("Mongodb Updating book ... " + book.title); 16 | } 17 | public void delete(String id){ 18 | System.out.println("Mongodb Deleting ... " + id); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/mongodb.book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module mongodb.book.service{ 2 | requires book.service; 3 | provides com.packt.spi.BookServiceProvider 4 | with com.packt.mongodb.MongoDbBookServiceProvider; 5 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/sqldb.book.service/com/packt/sqldb/SqlDbBookServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.packt.sqldb; 2 | 3 | import com.packt.spi.BookServiceProvider; 4 | import com.packt.sqldb.service.SqlDbBookService; 5 | import com.packt.service.BookService; 6 | 7 | public class SqlDbBookServiceProvider implements BookServiceProvider{ 8 | 9 | @Override 10 | public BookService getBookService(){ 11 | return new SqlDbBookService(); 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/sqldb.book.service/com/packt/sqldb/service/SqlDbBookService.java: -------------------------------------------------------------------------------- 1 | package com.packt.sqldb.service; 2 | 3 | import com.packt.service.BookService; 4 | import com.packt.model.Book; 5 | 6 | public class SqlDbBookService extends BookService{ 7 | public void create(Book book){ 8 | System.out.println("Sqldb Create book ... " + book.title); 9 | } 10 | public Book read(String id){ 11 | System.out.println("Sqldb Reading book ... " + id); 12 | return new Book(id, "Title", "Author"); 13 | } 14 | public void update(Book book){ 15 | System.out.println("Sqldb Updating book ... " + book.title); 16 | } 17 | public void delete(String id){ 18 | System.out.println("Sqldb Deleting ... " + id); 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter03/8_services/src/sqldb.book.service/module-info.java: -------------------------------------------------------------------------------- 1 | module sqldb.book.service{ 2 | requires book.service; 3 | provides com.packt.spi.BookServiceProvider 4 | with com.packt.sqldb.SqlDbBookServiceProvider; 5 | } -------------------------------------------------------------------------------- /Chapter03/9_jlink_modular_run_time_image/src/calculator/module-info.java: -------------------------------------------------------------------------------- 1 | module calculator{ 2 | requires math.util; 3 | } -------------------------------------------------------------------------------- /Chapter03/9_jlink_modular_run_time_image/src/math.util/module-info.java: -------------------------------------------------------------------------------- 1 | module math.util{ 2 | exports com.packt.math; 3 | } -------------------------------------------------------------------------------- /Chapter03/mvn_support_for_jigsaw/simple-module/src/main/simple.module/com/packt/SimpleModuleUsingMaven.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.util.*; 5 | import com.packt.util.SimpleModularUtil; 6 | public class SimpleModuleUsingMaven{ 7 | 8 | public static void main(String[] args) throws Exception{ 9 | SimpleModularUtil util = new SimpleModularUtil(); 10 | ObjectMapper objectMapper = new ObjectMapper(); 11 | Map data = new HashMap<>(); 12 | data.put("msg", util.message()); 13 | System.out.println(objectMapper.writeValueAsString(data)); 14 | } 15 | } -------------------------------------------------------------------------------- /Chapter03/mvn_support_for_jigsaw/simple-module/src/main/simple.module/module-info.java: -------------------------------------------------------------------------------- 1 | module simple.module{ 2 | requires jackson.databind; 3 | requires simple.util; 4 | } -------------------------------------------------------------------------------- /Chapter03/mvn_support_for_jigsaw/simple-util/src/main/simple.util/com/packt/SimpleModularUtil.java: -------------------------------------------------------------------------------- 1 | package com.packt.util; 2 | 3 | import java.util.*; 4 | public class SimpleModularUtil{ 5 | public String message(){ 6 | return "Hello World in JSON"; 7 | } 8 | } -------------------------------------------------------------------------------- /Chapter03/mvn_support_for_jigsaw/simple-util/src/main/simple.util/module-info.java: -------------------------------------------------------------------------------- 1 | module simple.util{ 2 | exports com.packt.util; 3 | } -------------------------------------------------------------------------------- /Chapter03/simple-modular-blog-proto/model-module/src/com.packt.model/com/packt/model/UserPrivilege.java: -------------------------------------------------------------------------------- 1 | package com.packt.model; 2 | 3 | public enum UserPrivilege{ 4 | can_create_post, can_manage_post, can_comment_on_post; 5 | } -------------------------------------------------------------------------------- /Chapter03/simple-modular-blog-proto/model-module/src/com.packt.model/module-info.java: -------------------------------------------------------------------------------- 1 | module com.packt.model{} -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$1.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$10.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$10.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$11.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$11.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$12.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$12.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$13.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$13.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$14.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$14.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$15.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$15.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$2.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$3.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$4.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$5.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$6.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$7.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$7.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$8.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$8.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$9.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$9.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$Demo$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$Demo$1.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional$Demo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional$Demo.class -------------------------------------------------------------------------------- /Chapter04/a/Chapter04Functional.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter04/a/Chapter04Functional.class -------------------------------------------------------------------------------- /Chapter04/c/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch04_functional.c.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Chapter04/c/api/TrafficUnit.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch04_functional.c.api; 2 | 3 | import com.packt.cookbook.ch04_functional.c.api.SpeedModel.RoadCondition; 4 | import com.packt.cookbook.ch04_functional.c.api.SpeedModel.TireCondition; 5 | import com.packt.cookbook.ch04_functional.c.api.Vehicle.VehicleType; 6 | 7 | public interface TrafficUnit { 8 | VehicleType getVehicleType(); 9 | int getHorsePower(); 10 | int getWeightPounds(); 11 | int getPayloadPounds(); 12 | int getPassengersCount(); 13 | double getSpeedLimitMph(); 14 | double getTraction(); 15 | RoadCondition getRoadCondition(); 16 | TireCondition getTireCondition(); 17 | int getTemperature(); 18 | } 19 | -------------------------------------------------------------------------------- /Chapter04/c/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch04_functional.c.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter04/c/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch04_functional.c.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | int getWeightPounds(); 7 | int getHorsePower(); 8 | 9 | enum VehicleType { 10 | CAR("Car"), 11 | TRUCK("Truck"), 12 | CAB_CREW("CabCrew"); 13 | 14 | private String type; 15 | private VehicleType(String type){ 16 | this.type = type; 17 | } 18 | public String getType(){return this.type;} 19 | 20 | @Override 21 | public String toString() { 22 | return this.name() + ":" + this.getType() ; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter05/Thing.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch05_streams; 2 | 3 | public class Thing{ 4 | private int someInt; 5 | 6 | public Thing(int i){ 7 | this.someInt = i; 8 | } 9 | 10 | public int getSomeInt() { 11 | return someInt; 12 | } 13 | 14 | public String getSomeStr() { 15 | return Integer.toString(someInt); 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter05/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch05_streams.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Chapter05/api/TrafficUnit.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch05_streams.api; 2 | 3 | import com.packt.cookbook.ch05_streams.api.SpeedModel.RoadCondition; 4 | import com.packt.cookbook.ch05_streams.api.SpeedModel.TireCondition; 5 | import com.packt.cookbook.ch05_streams.api.Vehicle.VehicleType; 6 | 7 | 8 | public interface TrafficUnit { 9 | VehicleType getVehicleType(); 10 | int getHorsePower(); 11 | int getWeightPounds(); 12 | int getPayloadPounds(); 13 | int getPassengersCount(); 14 | double getSpeedLimitMph(); 15 | double getTraction(); 16 | RoadCondition getRoadCondition(); 17 | TireCondition getTireCondition(); 18 | int getTemperature(); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter05/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch05_streams.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter05/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch05_streams.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | int getWeightPounds(); 7 | int getHorsePower(); 8 | 9 | enum VehicleType { 10 | CAR("Car"), 11 | TRUCK("Truck"), 12 | CAB_CREW("CabCrew"); 13 | 14 | private String type; 15 | VehicleType(String type){ 16 | this.type = type; 17 | } 18 | public String getType(){return this.type;} 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter06/image1.png -------------------------------------------------------------------------------- /Chapter06/mybatis/Family.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch06_db.mybatis; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Family { 7 | private int id; 8 | private String name; 9 | private final List members = new ArrayList<>(); 10 | 11 | public Family(){} 12 | 13 | public Family(String name){ 14 | this.name = name; 15 | } 16 | 17 | public int getId() { 18 | return id; 19 | } 20 | 21 | public String getName() { return name; } 22 | 23 | public List getMembers(){ return this.members; } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter06/mybatis/Person1.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch06_db.mybatis; 2 | 3 | public class Person1 { 4 | private int id; 5 | private int age; 6 | private String name; 7 | 8 | public Person1(){} //No constructor found in com.packt.cookbook.ch06_db.mybatis.Person1 matching [java.lang.Integer, java.lang.Integer, java.lang.String] 9 | public Person1(int age, String name){ 10 | this.age = age; 11 | this.name = name; 12 | } 13 | 14 | public int getId() { return id; } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "Person1{id=" + id + ", age=" + age + 23 | ", name='" + name + "'}"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter06/mybatis/Person2.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch06_db.mybatis; 2 | 3 | public class Person2 { 4 | private int id; 5 | private int age; 6 | private String name; 7 | 8 | private Family family; 9 | 10 | public Person2(){} 11 | public Person2(int age, String name, Family family){ 12 | this.age = age; 13 | this.name = name; 14 | this.family = family; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "Person2{id=" + id + ", age=" + age + 20 | ", name='" + name + "', family='" + 21 | (family == null ? "" : family.getName())+ "'}"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter07/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch07_concurrency.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Chapter07/api/TrafficUnit.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch07_concurrency.api; 2 | 3 | import com.packt.cookbook.ch07_concurrency.api.SpeedModel.RoadCondition; 4 | import com.packt.cookbook.ch07_concurrency.api.SpeedModel.TireCondition; 5 | import com.packt.cookbook.ch07_concurrency.api.Vehicle.VehicleType; 6 | 7 | 8 | public interface TrafficUnit { 9 | VehicleType getVehicleType(); 10 | int getHorsePower(); 11 | int getWeightPounds(); 12 | int getPayloadPounds(); 13 | int getPassengersCount(); 14 | double getSpeedLimitMph(); 15 | double getTraction(); 16 | RoadCondition getRoadCondition(); 17 | TireCondition getTireCondition(); 18 | int getTemperature(); 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter07/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch07_concurrency.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter07/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch07_concurrency.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | int getWeightPounds(); 7 | int getHorsePower(); 8 | 9 | enum VehicleType { 10 | CAR("Car"), 11 | TRUCK("Truck"), 12 | CAB_CREW("CabCrew"); 13 | 14 | private String type; 15 | VehicleType(String type){ 16 | this.type = type; 17 | } 18 | public String getType(){return this.type;} 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter08/10_connecting_process_pipe/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.PipeDemo -------------------------------------------------------------------------------- /Chapter08/10_connecting_process_pipe/src/process/com/packt/process/PipeDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | import java.io.*; 3 | import java.util.List; 4 | 5 | public class PipeDemo{ 6 | public static void main(String[] args) throws Exception{ 7 | List pipeline = List.of( 8 | new ProcessBuilder("cat", "iris.data.txt"), 9 | new ProcessBuilder("cut", "-d", ",", "-f", "5"), 10 | new ProcessBuilder("uniq", "-c").redirectOutput(ProcessBuilder.Redirect.INHERIT) 11 | ); 12 | 13 | List processes = ProcessBuilder.startPipeline(pipeline); 14 | 15 | int exitValue = processes.get(processes.size() - 1).waitFor(); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter08/10_connecting_process_pipe/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/11_managing_sub_process/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.ManageSubProcessDemo -------------------------------------------------------------------------------- /Chapter08/11_managing_sub_process/script.sh: -------------------------------------------------------------------------------- 1 | echo "Running tree command"; 2 | tree; 3 | sleep 5; 4 | echo "Running iostat command"; 5 | iostat; -------------------------------------------------------------------------------- /Chapter08/11_managing_sub_process/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/1_spawn_new_process/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.NewProcessDemo -------------------------------------------------------------------------------- /Chapter08/1_spawn_new_process/src/process/com/packt/process/NewProcessDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.io.IOException; 5 | 6 | public class NewProcessDemo{ 7 | public static void main(String [] args) throws IOException, InterruptedException{ 8 | ProcessBuilder pBuilder = new ProcessBuilder("free", "-m"); 9 | Process p = pBuilder.inheritIO().start(); 10 | if(p.waitFor(1, TimeUnit.SECONDS)){ 11 | System.out.println("process completed successfully"); 12 | }else{ 13 | System.out.println("waiting time elapsed, process did not complete"); 14 | System.out.println("destroying process forcibly"); 15 | p.destroyForcibly(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter08/1_spawn_new_process/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process {} -------------------------------------------------------------------------------- /Chapter08/2_redirect_to_file/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.RedirectFileDemo -------------------------------------------------------------------------------- /Chapter08/2_redirect_to_file/src/process/com/packt/process/RedirectFileDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.io.IOException; 4 | import java.io.File; 5 | import java.nio.file.Files; 6 | import java.nio.file.Paths; 7 | 8 | public class RedirectFileDemo{ 9 | public static void main(String[] args) 10 | throws IOException, InterruptedException{ 11 | ProcessBuilder pb = new ProcessBuilder("iostat", "-z"); 12 | pb.redirectError(new File("error")) 13 | .redirectOutput(new File("output")); 14 | Process p = pb.start(); 15 | int exitValue = p.waitFor(); 16 | 17 | System.out.println("Output"); 18 | Files.lines(Paths.get("output")).forEach(l -> System.out.println(l)); 19 | 20 | System.out.println("Error"); 21 | Files.lines(Paths.get("error")).forEach(l -> System.out.println(l)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter08/2_redirect_to_file/src/process/com/packt/process/input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter08/2_redirect_to_file/src/process/com/packt/process/input -------------------------------------------------------------------------------- /Chapter08/2_redirect_to_file/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process {} -------------------------------------------------------------------------------- /Chapter08/3_change_work_directory/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.ChangeWorkDirectoryDemo -------------------------------------------------------------------------------- /Chapter08/3_change_work_directory/src/process/com/packt/process/ChangeWorkDirectoryDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.io.IOException; 4 | import java.io.File; 5 | 6 | public class ChangeWorkDirectoryDemo{ 7 | public static void main(String[] args) 8 | throws IOException, InterruptedException{ 9 | ProcessBuilder pb = new ProcessBuilder(); 10 | 11 | pb.command("tree") 12 | .inheritIO(); 13 | 14 | pb.directory(new File("/home/")); 15 | 16 | Process p = pb.start(); 17 | 18 | int exitValue = p.waitFor(); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter08/3_change_work_directory/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/4_environment_variables/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.EnvironmentVariableDemo -------------------------------------------------------------------------------- /Chapter08/4_environment_variables/src/process/com/packt/process/EnvironmentVariableDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.io.IOException; 4 | import java.util.Map; 5 | 6 | public class EnvironmentVariableDemo{ 7 | public static void main(String[] args) 8 | throws IOException, InterruptedException { 9 | 10 | ProcessBuilder pb = new ProcessBuilder(); 11 | 12 | pb.command("printenv") 13 | .inheritIO(); 14 | 15 | Map environment = pb.environment(); 16 | environment.put("COOKBOOK_VAR1", "First variable"); 17 | environment.put("COOKBOOK_VAR2", "Second variable"); 18 | environment.put("COOKBOOK_VAR3", "Third variable"); 19 | 20 | Process p = pb.start(); 21 | 22 | int exitValue = p.waitFor(); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /Chapter08/4_environment_variables/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/5_running_shell_script/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.RunningShellScriptDemo -------------------------------------------------------------------------------- /Chapter08/5_running_shell_script/script.sh: -------------------------------------------------------------------------------- 1 | echo $MY_VARIABLE; 2 | echo "Running tree command"; 3 | tree; 4 | echo "Running iostat command" 5 | iostat; -------------------------------------------------------------------------------- /Chapter08/5_running_shell_script/src/process/com/packt/process/RunningShellScriptDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.io.IOException; 4 | import java.io.File; 5 | import java.util.Map; 6 | 7 | public class RunningShellScriptDemo{ 8 | public static void main(String[] args) 9 | throws IOException, InterruptedException { 10 | 11 | ProcessBuilder pb = new ProcessBuilder(); 12 | 13 | pb.directory(new File("/root")); 14 | 15 | Map environment = pb.environment(); 16 | environment.put("MY_VARIABLE", "From your parent Java process"); 17 | 18 | pb.command("/bin/bash", "script.sh").inheritIO(); 19 | 20 | Process p = pb.start(); 21 | 22 | int exitValue = p.waitFor(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter08/5_running_shell_script/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/6_current_process_info/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.CurrentProcessInfoDemo -------------------------------------------------------------------------------- /Chapter08/6_current_process_info/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/7_spawned_process_info/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) && 2 | java -p mods -m process/com.packt.process.SpawnedProcessInfoDemo -------------------------------------------------------------------------------- /Chapter08/7_spawned_process_info/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process {} -------------------------------------------------------------------------------- /Chapter08/8_manage_spawned_process/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.ManageSpawnedProcessDemo -------------------------------------------------------------------------------- /Chapter08/8_manage_spawned_process/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter08/9_enumerate_all_processes/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m process/com.packt.process.EnumerateProcessDemo -------------------------------------------------------------------------------- /Chapter08/9_enumerate_all_processes/src/process/com/packt/process/EnumerateProcessDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.process; 2 | 3 | import java.util.stream.Stream; 4 | 5 | public class EnumerateProcessDemo{ 6 | public static void main(String[] args) throws Exception{ 7 | Stream liveProcesses = ProcessHandle.allProcesses(); 8 | 9 | liveProcesses.forEach(ph -> { 10 | ProcessHandle.Info phInfo = ph.info(); 11 | System.out.println(phInfo.command().orElse("") +" " + phInfo.user().orElse("")); 12 | }); 13 | } 14 | } -------------------------------------------------------------------------------- /Chapter08/9_enumerate_all_processes/src/process/module-info.java: -------------------------------------------------------------------------------- 1 | module process{} -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/1_boot_demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/src/main/java/com/packt/boot_demo/BootDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/src/main/java/com/packt/boot_demo/SimpleViewController.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_demo; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class SimpleViewController{ 8 | 9 | @GetMapping("/message") 10 | public String message(){ 11 | return "message"; 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/1_boot_demo/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter09/1_boot_demo/src/main/resources/templates/message.html: -------------------------------------------------------------------------------- 1 |

Hello, this is a message from the Controller

2 |

The time now is [[${#dates.createNow()}]]

-------------------------------------------------------------------------------- /Chapter09/1_boot_demo/src/test/java/com/packt/boot_demo/BootDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/2_boot_db_demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/src/main/java/com/packt/boot_db_demo/BootDbDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootDbDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootDbDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 3 | spring.datasource.username=root 4 | spring.datasource.password=mohamed 5 | 6 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/src/main/resources/templates/detail.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Person

9 | All people 10 |

ID: [[${person.id}]]

11 |

First Name: [[${person.firstName}]]

12 |

Last Name: [[${person.lastName}]]

13 |

Place: [[${person.place}]]

14 | 15 | -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/src/main/resources/templates/list.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Persons!

9 | New Person 10 |
    11 |
  • 12 | [[${p.firstName}]] [[${p.lastName}]] lives in [[${p.place}]] 13 | Edit 14 | Delete 15 |
  • 16 |
17 | 18 | -------------------------------------------------------------------------------- /Chapter09/2_boot_db_demo/src/test/java/com/packt/boot_db_demo/BootDbDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootDbDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/3_boot_rest_demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/src/main/java/com/packt/boot_rest_demo/BootRestDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootRestDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootRestDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/src/main/java/com/packt/boot_rest_demo/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface PersonMapper { 9 | public List getPersons(); 10 | public Person getPerson(Integer id); 11 | public void save(Person person); 12 | public void insert(Person person); 13 | public void delete(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 3 | spring.datasource.username=root 4 | spring.datasource.password=mohamed 5 | 6 | mybatis.mapper-locations=classpath*:mappers/*.xml -------------------------------------------------------------------------------- /Chapter09/3_boot_rest_demo/src/test/java/com/packt/boot_rest_demo/BootRestDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootRestDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/4_boot_db_demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/src/main/java/com/packt/boot_db_demo/BootDbDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootDbDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootDbDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 3 | spring.datasource.username=root 4 | spring.datasource.password=mohamed 5 | 6 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/src/main/resources/templates/detail.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Person

9 | All people 10 |

ID: [[${person.id}]]

11 |

First Name: [[${person.firstName}]]

12 |

Last Name: [[${person.lastName}]]

13 |

Place: [[${person.place}]]

14 | 15 | -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/src/main/resources/templates/list.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Persons!

9 | New Person 10 |
    11 |
  • 12 | [[${p.firstName}]] [[${p.lastName}]] lives in [[${p.place}]] 13 | Edit 14 | Delete 15 |
  • 16 |
17 | 18 | -------------------------------------------------------------------------------- /Chapter09/4_boot_db_demo/src/test/java/com/packt/boot_db_demo/BootDbDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootDbDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/4_boot_multi_profile_complete/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/main/java/com/packt/boot_rest_demo/BootMultiProfileDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootMultiProfileDemo { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootMultiProfileDemo.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/main/java/com/packt/boot_rest_demo/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface PersonMapper { 9 | public List getPersons(); 10 | public Person getPerson(Integer id); 11 | public void save(Person person); 12 | public void insert(Person person); 13 | public void delete(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/main/resources/application-cloud.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://139.59.189.239/sample?useSSL=false 2 | spring.datasource.username=springboot 3 | spring.datasource.password=springboot 4 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 2 | spring.datasource.username=root 3 | spring.datasource.password=mohamed 4 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=local 2 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3 | 4 | mybatis.mapper-locations=classpath*:mappers/*.xml 5 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_complete/src/test/java/com/packt/boot_rest_demo/BootRestDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootRestDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/4_boot_multi_profile_incomplete/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/src/main/java/com/packt/boot_rest_demo/BootMultiProfileDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootMultiProfileDemo { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootMultiProfileDemo.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/src/main/java/com/packt/boot_rest_demo/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface PersonMapper { 9 | public List getPersons(); 10 | public Person getPerson(Integer id); 11 | public void save(Person person); 12 | public void insert(Person person); 13 | public void delete(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 4 | spring.datasource.username=root 5 | spring.datasource.password=mohamed 6 | 7 | mybatis.mapper-locations=classpath*:mappers/*.xml 8 | 9 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/4_boot_multi_profile_incomplete/src/test/java/com/packt/boot_rest_demo/BootRestDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootRestDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/5_boot_on_heroku/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/java/com/packt/restapp/AppController.java: -------------------------------------------------------------------------------- 1 | package com.packt.restapp; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class AppController { 8 | 9 | @GetMapping 10 | public String index(){ 11 | return "index"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/java/com/packt/restapp/BootMultiProfileDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.restapp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootMultiProfileDemo { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootMultiProfileDemo.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/java/com/packt/restapp/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.packt.restapp; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface PersonMapper { 9 | public List getPersons(); 10 | public Person getPerson(Integer id); 11 | public void save(Person person); 12 | public void insert(Person person); 13 | public void delete(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/resources/application-cloud.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://139.59.189.239/sample?useSSL=false 2 | spring.datasource.username=springboot 3 | spring.datasource.password=springboot 4 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/resources/application-heroku.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://lgg2gx1ha7yp2w0k.cbetxkdyhwsb.us-east-1.rds.amazonaws.com:3306/x81mhi5jwesjewjg?useSSL=false 2 | spring.datasource.username=zzu08pc38j33h89q 3 | spring.datasource.password=kormy0w2b0k3qqmp 4 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 2 | spring.datasource.username=root 3 | spring.datasource.password=mohamed 4 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=heroku 2 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3 | 4 | mybatis.mapper-locations=classpath*:mappers/*.xml 5 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Spring Boot App on Heroku

6 | 7 |

RESTful APIs supported

8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter09/5_boot_on_heroku/src/test/java/com/packt/restapp/BootRestDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.restapp; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootRestDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/6_boot_with_docker/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:17.10 2 | FROM openjdk:9-b177-jdk 3 | VOLUME /tmp 4 | ADD target/boot_docker-1.0.jar restapp.jar 5 | ENV JAVA_OPTS="-Dspring.profiles.active=cloud" 6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /restapp.jar" ] -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/main/java/com/packt/boot_rest_demo/BootMultiProfileDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootMultiProfileDemo { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootMultiProfileDemo.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/main/java/com/packt/boot_rest_demo/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | 7 | @Mapper 8 | public interface PersonMapper { 9 | public List getPersons(); 10 | public Person getPerson(Integer id); 11 | public void save(Person person); 12 | public void insert(Person person); 13 | public void delete(Integer id); 14 | } 15 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/main/resources/application-cloud.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://139.59.189.239/sample?useSSL=false 2 | spring.datasource.username=springboot 3 | spring.datasource.password=springboot 4 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 2 | spring.datasource.username=root 3 | spring.datasource.password=root 4 | -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=local 2 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 3 | 4 | mybatis.mapper-locations=classpath*:mappers/*.xml 5 | mybatis.configuration.map-underscore-to-camel-case=true -------------------------------------------------------------------------------- /Chapter09/6_boot_with_docker/src/test/java/com/packt/boot_rest_demo/BootRestDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_rest_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootRestDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter09/7_boot_micrometer/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/src/main/java/com/packt/boot_db_demo/BootDbDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootDbDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootDbDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost/sample?useSSL=false 3 | spring.datasource.username=root 4 | spring.datasource.password=mohamed 5 | 6 | mybatis.configuration.map-underscore-to-camel-case=true 7 | 8 | management.endpoints.web.exposure.include=prometheus,metrics,health,info -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/src/main/resources/templates/detail.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Person

9 | All people 10 |

ID: [[${person.id}]]

11 |

First Name: [[${person.firstName}]]

12 |

Last Name: [[${person.lastName}]]

13 |

Place: [[${person.place}]]

14 | 15 | -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/src/main/resources/templates/list.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 |

Persons!

9 | New Person 10 |
    11 |
  • 12 | [[${p.firstName}]] [[${p.lastName}]] lives in [[${p.place}]] 13 | Edit 14 | Delete 15 |
  • 16 |
17 | 18 | -------------------------------------------------------------------------------- /Chapter09/7_boot_micrometer/src/test/java/com/packt/boot_db_demo/BootDbDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.packt.boot_db_demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BootDbDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter10/1_making_http_get/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.HttpGetDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/1_making_http_get/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.HttpGetDemo -------------------------------------------------------------------------------- /Chapter10/1_making_http_get/src/http.client.demo/com/packt/HttpGetDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import java.net.http.*; 4 | import java.net.URI; 5 | 6 | public class HttpGetDemo{ 7 | public static void main(String [] args) throws Exception{ 8 | HttpClient client = HttpClient 9 | .newBuilder() 10 | .build(); 11 | 12 | HttpRequest request = HttpRequest 13 | .newBuilder(new URI("http://httpbin.org/get")) 14 | .GET() 15 | .version(HttpClient.Version.HTTP_1_1) 16 | .build(); 17 | 18 | HttpResponse response = client.send(request, 19 | HttpResponse.BodyHandlers.ofString()); 20 | 21 | System.out.println("Status code: " + response.statusCode()); 22 | System.out.println("Response Body: " + response.body()); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /Chapter10/1_making_http_get/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires java.net.http; 3 | } -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/mods/jackson.annotations.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/2_making_http_post/mods/jackson.annotations.jar -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/mods/jackson.core.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/2_making_http_post/mods/jackson.core.jar -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/mods/jackson.databind.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/2_making_http_post/mods/jackson.databind.jar -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.HttpPostDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.HttpPostDemo -------------------------------------------------------------------------------- /Chapter10/2_making_http_post/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires java.net.http; 3 | requires jackson.databind; 4 | requires jackson.core; 5 | requires jackson.annotations; 6 | } -------------------------------------------------------------------------------- /Chapter10/3_making_http_request_protected_res/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.HttpRequestProtectedResDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/3_making_http_request_protected_res/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.HttpRequestProtectedResDemo -------------------------------------------------------------------------------- /Chapter10/3_making_http_request_protected_res/src/http.client.demo/com/packt/UsernamePasswordAuthenticator.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import java.net.Authenticator; 4 | import java.net.PasswordAuthentication; 5 | 6 | public class UsernamePasswordAuthenticator extends Authenticator{ 7 | 8 | private String username; 9 | private String password; 10 | 11 | public UsernamePasswordAuthenticator(){} 12 | 13 | public UsernamePasswordAuthenticator ( String username, String password){ 14 | this.username = username; 15 | this.password = password; 16 | } 17 | 18 | @Override 19 | protected PasswordAuthentication getPasswordAuthentication(){ 20 | return new PasswordAuthentication(username, password.toCharArray()); 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter10/3_making_http_request_protected_res/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires java.net.http; 3 | } -------------------------------------------------------------------------------- /Chapter10/4_async_http_request/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.AsyncHttpRequestDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/4_async_http_request/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.AsyncHttpRequestDemo -------------------------------------------------------------------------------- /Chapter10/4_async_http_request/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires java.net.http; 3 | } -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/mods/commons.codec.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_1_apache_http_demo_response_handler/mods/commons.codec.jar -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/mods/commons.logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_1_apache_http_demo_response_handler/mods/commons.logging.jar -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/mods/httpclient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_1_apache_http_demo_response_handler/mods/httpclient.jar -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/mods/httpcore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_1_apache_http_demo_response_handler/mods/httpcore.jar -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.ApacheHttpClientResponseHandlerDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.ApacheHttpClientResponseHandlerDemo -------------------------------------------------------------------------------- /Chapter10/5_1_apache_http_demo_response_handler/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires httpclient; 3 | requires httpcore; 4 | requires commons.logging; 5 | requires commons.codec; 6 | 7 | } -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/mods/commons.codec.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_apache_http_demo/mods/commons.codec.jar -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/mods/commons.logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_apache_http_demo/mods/commons.logging.jar -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/mods/httpclient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_apache_http_demo/mods/httpclient.jar -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/mods/httpcore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/5_apache_http_demo/mods/httpcore.jar -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.ApacheHttpClientDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.ApacheHttpClientDemo -------------------------------------------------------------------------------- /Chapter10/5_apache_http_demo/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires httpclient; 3 | requires httpcore; 4 | requires commons.logging; 5 | requires commons.codec; 6 | 7 | } -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/commons.codec.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/commons.codec.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/commons.logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/commons.logging.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/httpasyncclient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/httpasyncclient.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/httpclient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/httpclient.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/httpcore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/httpcore.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/httpcore.nio.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/httpcore.nio.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/httpmime.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/httpmime.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/json.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/json.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/mods/unirest.java.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter10/6_unirest_http_demo/mods/unirest.java.jar -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods -p mods --module-source-path src src\http.client.demo\com\packt\*.java src\http.client.demo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m http.client.demo/com.packt.UnirestHttpClientDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods -p mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m http.client.demo/com.packt.UnirestHttpClientDemo -------------------------------------------------------------------------------- /Chapter10/6_unirest_http_demo/src/http.client.demo/module-info.java: -------------------------------------------------------------------------------- 1 | module http.client.demo{ 2 | requires httpasyncclient; 3 | requires httpclient; 4 | requires httpmime; 5 | requires json; 6 | requires unirest.java; 7 | requires httpcore; 8 | requires httpcore.nio; 9 | requires commons.logging; 10 | requires commons.codec; 11 | } -------------------------------------------------------------------------------- /Chapter11/Epsilon.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch11_memory; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Epsilon { 7 | public static void main(String... args) { 8 | List list = new ArrayList<>(); 9 | int n = 4 * 1024 * 1024; 10 | for(int i=0; i < n; i++){ 11 | list.add(new byte[1024]); 12 | byte[] arr = new byte[1024]; 13 | } 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter11/walk/Clazz01.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch11_memory.walk; 2 | 3 | public class Clazz01 { 4 | 5 | public void method(){ 6 | System.out.println("\nClazz01 called by "+StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass().getSimpleName()); 7 | new Clazz03().method("Do something"); 8 | new Clazz02().method(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter11/walk/Clazz02.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch11_memory.walk; 2 | 3 | public class Clazz02 { 4 | 5 | public void method(){ 6 | //System.out.println("\nClazz02 called by "+StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass().getSimpleName()); 7 | new Clazz03().method(null); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter12/4_oo_programming/Car.java: -------------------------------------------------------------------------------- 1 | public class Car{ 2 | public Engine engine; 3 | public Dimensions dimensions; 4 | public String brandName; 5 | public String commercialName; 6 | public int modelYear; 7 | 8 | public Car(){} 9 | 10 | public Car(Engine engine, Dimensions dimensions, 11 | String brandName, String commercialName, int modelYear){ 12 | this.engine = engine; 13 | this.dimensions = dimensions; 14 | this.brandName = brandName; 15 | this.commercialName = commercialName; 16 | this.modelYear = modelYear; 17 | } 18 | } -------------------------------------------------------------------------------- /Chapter12/4_oo_programming/Dimensions.java: -------------------------------------------------------------------------------- 1 | public class Dimensions{ 2 | public int length; 3 | public int width; 4 | public int height; 5 | 6 | public Dimensions(){} 7 | 8 | public Dimensions(int length, int width, int height){ 9 | this.length = length; 10 | this.width = width; 11 | this.height = height; 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter12/4_oo_programming/Engine.java: -------------------------------------------------------------------------------- 1 | public class Engine{ 2 | public String type; 3 | public int cylinders; 4 | public int displacement; 5 | 6 | public Engine(){} 7 | 8 | public Engine(String type, int cylinders, int displacement){ 9 | this.type = type; 10 | this.cylinders = cylinders; 11 | this.displacement = displacement; 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter12/4_oo_programming/history: -------------------------------------------------------------------------------- 1 | "Hello World" 2 | String msg = "Hello, %s. Good Morning"; 3 | System.out.println(String.format(msg, "Friend")) 4 | int someInt = 10; 5 | boolean someBool = false; 6 | if ( someBool ) { 7 | System.out.println("True block executed"); 8 | } 9 | if ( someBool ) { 10 | System.out.println("True block executed"); 11 | }else{ 12 | System.out.println("False block executed"); 13 | } 14 | for ( int i = 0; i < 10; i++){ 15 | System.out.println("I is : " + i); 16 | } -------------------------------------------------------------------------------- /Chapter12/6_jshell_api/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\jshell\com\packt\*.java src\jshell\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m jshell/com.packt.JshellJavaApiDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter12/6_jshell_api/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m jshell/com.packt.JshellJavaApiDemo -------------------------------------------------------------------------------- /Chapter12/6_jshell_api/src/jshell/module-info.java: -------------------------------------------------------------------------------- 1 | module jshell{ 2 | requires jdk.jshell; 3 | } -------------------------------------------------------------------------------- /Chapter13/1_2_print_calendar/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\datedemo\com\packt\*.java src\datedemo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m datedemo/com.packt.Main 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter13/1_2_print_calendar/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m gui/com.packt.CreateGuiDemo -------------------------------------------------------------------------------- /Chapter13/1_2_print_calendar/src/datedemo/module-info.java: -------------------------------------------------------------------------------- 1 | module datedemo{ 2 | 3 | } -------------------------------------------------------------------------------- /Chapter13/1_create_date_time/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\datedemo\com\packt\*.java src\datedemo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m datedemo/com.packt.Main 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter13/1_create_date_time/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m gui/com.packt.CreateGuiDemo -------------------------------------------------------------------------------- /Chapter13/1_create_date_time/src/datedemo/module-info.java: -------------------------------------------------------------------------------- 1 | module datedemo{ 2 | 3 | } -------------------------------------------------------------------------------- /Chapter13/2_create_tz_date_time/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\datedemo\com\packt\*.java src\datedemo\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m datedemo/com.packt.Main 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter13/2_create_tz_date_time/run.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | java -p mods -m gui/com.packt.CreateGuiDemo -------------------------------------------------------------------------------- /Chapter13/2_create_tz_date_time/src/datedemo/module-info.java: -------------------------------------------------------------------------------- 1 | module datedemo{ 2 | 3 | } -------------------------------------------------------------------------------- /Chapter14/api/Car.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.api; 2 | 3 | public interface Car extends Vehicle { 4 | int getPassengersCount(); 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Chapter14/api/TrafficUnit.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.api; 2 | 3 | import com.packt.cookbook.ch14_testing.api.SpeedModel.RoadCondition; 4 | import com.packt.cookbook.ch14_testing.api.SpeedModel.TireCondition; 5 | import com.packt.cookbook.ch14_testing.api.Vehicle.VehicleType; 6 | 7 | 8 | public interface TrafficUnit { 9 | VehicleType getVehicleType(); 10 | int getHorsePower(); 11 | int getWeightPounds(); 12 | int getPayloadPounds(); 13 | int getPassengersCount(); 14 | double getSpeedLimitMph(); 15 | double getTraction(); 16 | RoadCondition getRoadCondition(); 17 | TireCondition getTireCondition(); 18 | int getTemperature(); 19 | default double getSpeed(){ return 0.0; } 20 | } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter14/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter14/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | int getWeightPounds(); 7 | int getHorsePower(); 8 | 9 | enum VehicleType { 10 | CAR("Car"), 11 | TRUCK("Truck"), 12 | CAB_CREW("CabCrew"); 13 | 14 | private String type; 15 | VehicleType(String type){ 16 | this.type = type; 17 | } 18 | public String getType(){return this.type;} 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter14/factories/FactorySpeedModel.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.factories; 2 | 3 | import com.packt.cookbook.ch14_testing.api.SpeedModel; 4 | 5 | public class FactorySpeedModel { 6 | public static SpeedModel getSpeedModel(){ 7 | return (t, wp, hp) -> { 8 | double weightPower = 2.0 * hp * 746 * 32.174 / wp; 9 | return Math.round(Math.sqrt(t * weightPower) * 0.68); 10 | }; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Chapter14/process/Process.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch14_testing.process; 2 | 3 | public enum Process { 4 | AVERAGE_SPEED, 5 | TRAFFIC_DENSITY 6 | } 7 | -------------------------------------------------------------------------------- /Chapter15/b_lambdas/Chapter15Upgrades.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch15_new_way.b_lambdas; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.function.Function; 6 | 7 | public class Chapter15Upgrades { 8 | public static void main(String... args) { 9 | Function noneByDefault = notUsed -> 0; // currently 10 | // Function noneByDefault1 = _ -> 0; // proposed 11 | 12 | 13 | Map map = new HashMap<>(); 14 | String key = "theInitialKey"; 15 | 16 | /* 17 | map.computeIfAbsent(key, _ -> { 18 | String key = "theShadowKey"; // shadow variable 19 | return key.length(); 20 | }); 21 | */ 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter15/c_enum/api/Truck.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch15_new_way.c_enum.api; 2 | 3 | public interface Truck extends Vehicle { 4 | int getPayloadPounds(); 5 | } 6 | -------------------------------------------------------------------------------- /Chapter15/c_enum/api/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.packt.cookbook.ch15_new_way.c_enum.api; 2 | 3 | public interface Vehicle { 4 | void setSpeedModel(SpeedModel speedModel); 5 | double getSpeedMph(double timeSec); 6 | int getWeightPounds(); 7 | } 8 | -------------------------------------------------------------------------------- /Chapter16/101_student_data_processor/build-jar.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\student.processor\com\packt\processor\*.java src\student.processor\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\student.processor\com\packt\processor\students mods\student.processor\com\packt\processor 8 | mkdir mlib 9 | jar --create --file=mlib/student.processor.jar -C mods/student.processor . 10 | goto end 11 | 12 | :failedCompilation 13 | echo 'Compilation failed' 14 | 15 | :end 16 | echo 'Bye!!' 17 | -------------------------------------------------------------------------------- /Chapter16/101_student_data_processor/build-jar.sh: -------------------------------------------------------------------------------- 1 | javac -d mods --module-source-path src $(find src -name *.java) 2 | cp src/student.processor/com/packt/processor/students mods/student.processor/com/packt/processor 3 | mkdir -p mlib 4 | jar --create --file=mlib/student.processor.jar -C mods/student.processor . 5 | -------------------------------------------------------------------------------- /Chapter16/101_student_data_processor/src/student.processor/com/packt/processor/ParentEducation.java: -------------------------------------------------------------------------------- 1 | package com.packt.processor; 2 | 3 | public enum ParentEducation{ 4 | NONE, PRIMARY, FIVE_NINE_GRADE, SECONDARY, HIGHER; 5 | } -------------------------------------------------------------------------------- /Chapter16/101_student_data_processor/src/student.processor/com/packt/processor/StudentDataProcessor.java: -------------------------------------------------------------------------------- 1 | package com.packt.processor; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.io.IOException; 6 | import java.util.Scanner; 7 | 8 | public class StudentDataProcessor{ 9 | public List loadStudent() throws IOException{ 10 | Scanner reader = new Scanner(getClass() 11 | .getModule() 12 | .getResourceAsStream("com/packt/processor/students") 13 | ); 14 | 15 | List students = new ArrayList<>(); 16 | while(reader.hasNext()){ 17 | String line = reader.nextLine(); 18 | String[] elements = line.split(";"); 19 | Student student = new Student(elements); 20 | students.add(student); 21 | } 22 | 23 | return students; 24 | } 25 | } -------------------------------------------------------------------------------- /Chapter16/101_student_data_processor/src/student.processor/module-info.java: -------------------------------------------------------------------------------- 1 | module student.processor{ 2 | exports com.packt.processor; 3 | } -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p mods -m gui/com.packt.TiffReaderDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.TiffReaderDemo -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/sample.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/13_tiff_reader/sample.tif -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/src/gui/com/packt/BrowserDemo$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/13_tiff_reader/src/gui/com/packt/BrowserDemo$1.class -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/src/gui/com/packt/BrowserDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/13_tiff_reader/src/gui/com/packt/BrowserDemo.class -------------------------------------------------------------------------------- /Chapter16/13_tiff_reader/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.controls; 3 | requires javafx.graphics; 4 | requires java.desktop; 5 | } -------------------------------------------------------------------------------- /Chapter16/1_create_javafx_gui/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:\openjfx11\javafx-sdk-11\lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p G:\openjfx11\javafx-sdk-11\lib;mods -m gui/com.packt.CreateGuiDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 12 | 'Compilation failed' 13 | 14 | :end 15 | echo 'Bye!!' 16 | -------------------------------------------------------------------------------- /Chapter16/1_create_javafx_gui/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "mods:/g/openjfx11/javafx-sdk-11/lib" -m gui/com.packt.CreateGuiDemo -------------------------------------------------------------------------------- /Chapter16/1_create_javafx_gui/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | exports com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/2_fxml_gui/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:\openjfx11\javafx-sdk-11\lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\*.fxml mods\gui\com\packt 8 | java -p "G:\openjfx11\javafx-sdk-11\lib;mods" -m gui/com.packt.FxmlGuiDemo 9 | goto end 10 | 11 | :failedCompilation 12 | echo 'Compilation failed' 13 | 14 | :end 15 | echo 'Bye!!' 16 | -------------------------------------------------------------------------------- /Chapter16/2_fxml_gui/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src\gui\com\packt\*.fxml mods\gui\com\packt 3 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.FxmlGuiDemo -------------------------------------------------------------------------------- /Chapter16/2_fxml_gui/src/gui/com/packt/FxmlGuiDemo.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | import javafx.application.Application; 4 | import javafx.scene.Scene; 5 | import javafx.stage.Stage; 6 | import javafx.scene.layout.Pane; 7 | import javafx.fxml.FXMLLoader; 8 | import java.io.IOException; 9 | 10 | public class FxmlGuiDemo extends Application{ 11 | 12 | @Override 13 | public void start(Stage stage) throws IOException{ 14 | 15 | FXMLLoader loader = new FXMLLoader(); 16 | Pane pane = (Pane)loader.load(getClass() 17 | .getModule() 18 | .getResourceAsStream("com/packt/fxml_age_calc_gui.fxml") 19 | ); 20 | Scene scene = new Scene(pane,300, 250); 21 | stage.setTitle("Age calculator"); 22 | stage.setScene(scene); 23 | stage.show(); 24 | } 25 | public static void main(String[] args) { 26 | Application.launch(args); 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /Chapter16/2_fxml_gui/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | requires javafx.fxml; 5 | 6 | opens com.packt; 7 | } -------------------------------------------------------------------------------- /Chapter16/3_css_javafx/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\*.css mods\gui\com\packt 8 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.CssJavaFxDemo 9 | goto end 10 | 11 | :failedCompilation 12 | echo 'Compilation failed' 13 | 14 | :end 15 | echo 'Bye!!' 16 | -------------------------------------------------------------------------------- /Chapter16/3_css_javafx/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src\gui\com\packt\*.css mods\gui\com\packt 3 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.CssJavaFxDemo -------------------------------------------------------------------------------- /Chapter16/3_css_javafx/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | requires javafx.fxml; 5 | 6 | opens com.packt; 7 | } -------------------------------------------------------------------------------- /Chapter16/4_bar_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p "G:/openjfx11/javafx-sdk-11/lib;mlib\student.processor.jar" -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods;mlib\student.processor.jar" -m gui/com.packt.BarChartDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/4_bar_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib:mlib/student.processor.jar -d mods --module-source-path src $(find src -name *.java) 2 | java -p /g/openjfx11/javafx-sdk-11/lib:mods:mlib/student.processor.jar -m gui/com.packt.BarChartDemo 3 | -------------------------------------------------------------------------------- /Chapter16/4_bar_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | requires student.processor; 6 | 7 | opens com.packt; 8 | } -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\crude-oil mods\gui\com\packt\ 8 | copy src\gui\com\packt\brent-oil mods\gui\com\packt\ 9 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.AreaChartDemo 10 | goto end 11 | 12 | :failedCompilation 13 | echo 'Compilation failed' 14 | 15 | :end 16 | echo 'Bye!!' 17 | -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src/gui/com/packt/crude-oil mods/gui/com/packt/ 3 | cp src/gui/com/packt/brent-oil mods/gui/com/packt/ 4 | java -p /g/openjfx11/javafx-sdk-11/lib:mods -m gui/com.packt.AreaChartDemo 5 | -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/com/packt/Marks.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | public class Marks{ 4 | public String id; 5 | public Double unitTests; 6 | public Double midTerm; 7 | public Double finalTerm; 8 | 9 | public Marks(String[] elements){ 10 | id = elements[0]; 11 | unitTests = Double.parseDouble(elements[1]); 12 | midTerm = Double.parseDouble(elements[2]); 13 | finalTerm = Double.parseDouble(elements[3]); 14 | } 15 | 16 | public Double getUnitTests(){ return unitTests; } 17 | public Double getMidTerm(){ return midTerm; } 18 | public Double getFinalTerm(){ return finalTerm; } 19 | } -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/com/packt/OilPrice.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | public class OilPrice{ 4 | public String period; 5 | public Double value; 6 | 7 | @Override 8 | public String toString(){ 9 | return period + " = " + value; 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/com/packt/brent-oil: -------------------------------------------------------------------------------- 1 | 17-Feb 55.09 2 | 17-Jan 55.7 3 | 16-Nov 50.47 4 | 16-Sep 49.06 5 | 16-Jul 42.46 6 | 16-May 49.69 7 | 16-Mar 39.6 8 | 16-Jan 34.74 9 | 15-Nov 44.61 10 | 15-Sep 48.37 11 | 15-Jul 52.21 12 | 15-May 65.56 13 | 15-Mar 55.11 14 | 15-Jan 52.99 15 | 14-Nov 70.15 16 | 14-Oct 85.86 17 | 14-Sep 94.67 18 | 14-Aug 103.19 19 | 14-Jun 112.36 -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/com/packt/crude-oil: -------------------------------------------------------------------------------- 1 | 17-Feb 52.18 2 | 17-Jan 52.81 3 | 16-Nov 49.44 4 | 16-Sep 48.24 5 | 16-Jul 41.6 6 | 16-May 49.1 7 | 16-Mar 38.34 8 | 16-Jan 33.62 9 | 15-Nov 41.65 10 | 15-Sep 45.09 11 | 15-Jul 47.12 12 | 15-May 60.3 13 | 15-Mar 47.6 14 | 15-Jan 48.24 15 | 14-Nov 66.15 16 | 14-Oct 80.54 17 | 14-Sep 91.16 18 | 14-Aug 95.96 19 | 14-Jun 105.37 -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/com/packt/marks: -------------------------------------------------------------------------------- 1 | 0001,85,90,93 2 | 0002,65,60,70 3 | 0003,70,85,85 4 | 0004,88,90,95 5 | 0005,58,55,59 6 | 0006,65,74,79 7 | 0007,40,44,49 8 | 0008,95,95,98 9 | 0009,98,98,99 10 | 0010,85,85,89 11 | 0011,63,65,70 12 | 0012,81,83,89 13 | 0013,50,50,55 14 | 0014,51,52,53 15 | 0015,61,62,63 -------------------------------------------------------------------------------- /Chapter16/5_2_area_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\crude-oil mods\gui\com\packt\ 8 | copy src\gui\com\packt\brent-oil mods\gui\com\packt\ 9 | java -p G:/openjfx11/javafx-sdk-11/lib;mods -m gui/com.packt.LineChartDemo 10 | goto end 11 | 12 | :failedCompilation 13 | echo 'Compilation failed' 14 | 15 | :end 16 | echo 'Bye!!' 17 | -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src/gui/com/packt/crude-oil mods/gui/com/packt/ 3 | cp src/gui/com/packt/brent-oil mods/gui/com/packt/ 4 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.LineChartDemo 5 | -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/src/gui/com/packt/OilPrice.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | public class OilPrice{ 4 | public String period; 5 | public Double value; 6 | 7 | @Override 8 | public String toString(){ 9 | return period + " = " + value; 10 | } 11 | } -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/src/gui/com/packt/brent-oil: -------------------------------------------------------------------------------- 1 | 17-Feb 55.09 2 | 17-Jan 55.7 3 | 16-Nov 50.47 4 | 16-Sep 49.06 5 | 16-Jul 42.46 6 | 16-May 49.69 7 | 16-Mar 39.6 8 | 16-Jan 34.74 9 | 15-Nov 44.61 10 | 15-Sep 48.37 11 | 15-Jul 52.21 12 | 15-May 65.56 13 | 15-Mar 55.11 14 | 15-Jan 52.99 15 | 14-Nov 70.15 16 | 14-Oct 85.86 17 | 14-Sep 94.67 18 | 14-Aug 103.19 19 | 14-Jun 112.36 -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/src/gui/com/packt/crude-oil: -------------------------------------------------------------------------------- 1 | 17-Feb 52.18 2 | 17-Jan 52.81 3 | 16-Nov 49.44 4 | 16-Sep 48.24 5 | 16-Jul 41.6 6 | 16-May 49.1 7 | 16-Mar 38.34 8 | 16-Jan 33.62 9 | 15-Nov 41.65 10 | 15-Sep 45.09 11 | 15-Jul 47.12 12 | 15-May 60.3 13 | 15-Mar 47.6 14 | 15-Jan 48.24 15 | 14-Nov 66.15 16 | 14-Oct 80.54 17 | 14-Sep 91.16 18 | 14-Aug 95.96 19 | 14-Jun 105.37 -------------------------------------------------------------------------------- /Chapter16/5_3_line_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/5_4_bubble_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\store mods\gui\com\packt\ 8 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.BubbleChartDemo 9 | goto end 10 | 11 | :failedCompilation 12 | echo 'Compilation failed' 13 | 14 | :end 15 | echo 'Bye!!' 16 | -------------------------------------------------------------------------------- /Chapter16/5_4_bubble_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src/gui/com/packt/store mods/gui/com/packt/ 3 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.BubbleChartDemo 4 | -------------------------------------------------------------------------------- /Chapter16/5_4_bubble_charts/src/gui/com/packt/StoreVisit.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | public class StoreVisit{ 4 | Integer hour; 5 | Integer visits; 6 | Integer sales; 7 | 8 | public StoreVisit(String[] elements){ 9 | hour = Integer.parseInt(elements[0]); 10 | visits = Integer.parseInt(elements[1]); 11 | sales = Integer.parseInt(elements[2]); 12 | } 13 | 14 | public Integer getSales() { return sales; } 15 | } -------------------------------------------------------------------------------- /Chapter16/5_4_bubble_charts/src/gui/com/packt/store: -------------------------------------------------------------------------------- 1 | 8,12,100 2 | 9,20,120 3 | 10,25,150 4 | 11,30,150 5 | 12,40,120 6 | 13,50,120 7 | 14,20,100 8 | 15,20,120 9 | 16,25,150 10 | 17,30,200 11 | 18,50,200 12 | 19,60,250 13 | 20,30,400 14 | 21,25,100 15 | 22,20,100 -------------------------------------------------------------------------------- /Chapter16/5_4_bubble_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/5_5_scatter_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | copy src\gui\com\packt\wickets mods\gui\com\packt\ 8 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.ScatterChartDemo 9 | goto end 10 | 11 | :failedCompilation 12 | echo 'Compilation failed' 13 | 14 | :end 15 | echo 'Bye!!' 16 | -------------------------------------------------------------------------------- /Chapter16/5_5_scatter_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | cp src/gui/com/packt/wickets mods/gui/com/packt/ 3 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.ScatterChartDemo 4 | -------------------------------------------------------------------------------- /Chapter16/5_5_scatter_charts/src/gui/com/packt/FallOfWicket.java: -------------------------------------------------------------------------------- 1 | package com.packt; 2 | 3 | public class FallOfWicket{ 4 | Double over; 5 | Integer score; 6 | 7 | public FallOfWicket(String[] elements){ 8 | over = Double.parseDouble(elements[1]); 9 | score = Integer.parseInt(elements[2]); 10 | } 11 | 12 | @Override 13 | public String toString(){ 14 | return over +"-" + score; 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter16/5_5_scatter_charts/src/gui/com/packt/wickets: -------------------------------------------------------------------------------- 1 | NZ,0.2,0 2 | NZ,20.3,120 3 | NZ,30.6,158 4 | NZ,40.5,204 5 | NZ,42.4,213 6 | NZ,43.3,216 7 | NZ,45.1,224 8 | NZ,45.5,225 9 | NZ,49.2,237 10 | IND,7.1,21 11 | IND,11.4,40 12 | IND,18.4,72 13 | IND,19.2,73 14 | IND,31.1,139 15 | IND,39.3,172 16 | IND,40.1,180 17 | IND,40.5,183 18 | IND,48.5,232 19 | IND,49.3,236 -------------------------------------------------------------------------------- /Chapter16/5_5_scatter_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/5_pie_charts/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p "G:/openjfx11/javafx-sdk-11/lib;mlib\student.processor.jar" -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods;mlib\student.processor.jar" -m gui/com.packt.PieChartDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/5_pie_charts/run.sh: -------------------------------------------------------------------------------- 1 | javac -p "/g/openjfx11/javafx-sdk-11/lib:mlib/student.processor.jar" -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods:mlib/student.processor.jar" -m gui/com.packt.PieChartDemo 3 | -------------------------------------------------------------------------------- /Chapter16/5_pie_charts/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.graphics; 3 | requires javafx.controls; 4 | 5 | requires student.processor; 6 | 7 | opens com.packt; 8 | } -------------------------------------------------------------------------------- /Chapter16/6_embed_html/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.BrowserDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/6_embed_html/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.BrowserDemo -------------------------------------------------------------------------------- /Chapter16/6_embed_html/src/gui/com/packt/BrowserDemo$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/6_embed_html/src/gui/com/packt/BrowserDemo$1.class -------------------------------------------------------------------------------- /Chapter16/6_embed_html/src/gui/com/packt/BrowserDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/6_embed_html/src/gui/com/packt/BrowserDemo.class -------------------------------------------------------------------------------- /Chapter16/6_embed_html/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.controls; 3 | requires javafx.web; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/7_embed_audio_video/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.EmbedAudioVideoDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/7_embed_audio_video/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.EmbedAudioVideoDemo -------------------------------------------------------------------------------- /Chapter16/7_embed_audio_video/sample_video1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/7_embed_audio_video/sample_video1.mp4 -------------------------------------------------------------------------------- /Chapter16/7_embed_audio_video/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.controls; 3 | requires javafx.media; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/8_effects_demo/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:/openjfx11/javafx-sdk-11/lib;mods" -m gui/com.packt.EffectsDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/8_effects_demo/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.EffectsDemo -------------------------------------------------------------------------------- /Chapter16/8_effects_demo/src/gui/com/packt/BrowserDemo$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/8_effects_demo/src/gui/com/packt/BrowserDemo$1.class -------------------------------------------------------------------------------- /Chapter16/8_effects_demo/src/gui/com/packt/BrowserDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/8_effects_demo/src/gui/com/packt/BrowserDemo.class -------------------------------------------------------------------------------- /Chapter16/8_effects_demo/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.controls; 3 | requires javafx.graphics; 4 | 5 | opens com.packt; 6 | } -------------------------------------------------------------------------------- /Chapter16/9_robot_api/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | javac -p G:\openjfx11\javafx-sdk-11\lib -d mods --module-source-path src src\gui\com\packt\*.java src\gui\module-info.java 3 | 4 | if %errorlevel% == 1 goto failedCompilation 5 | 6 | :runCode 7 | java -p "G:\openjfx11\javafx-sdk-11\lib;mods" -m gui/com.packt.RobotAPIDemo 8 | goto end 9 | 10 | :failedCompilation 11 | echo 'Compilation failed' 12 | 13 | :end 14 | echo 'Bye!!' 15 | -------------------------------------------------------------------------------- /Chapter16/9_robot_api/run.sh: -------------------------------------------------------------------------------- 1 | javac -p /g/openjfx11/javafx-sdk-11/lib -d mods --module-source-path src $(find src -name *.java) 2 | java -p "/g/openjfx11/javafx-sdk-11/lib:mods" -m gui/com.packt.RobotAPIDemo -------------------------------------------------------------------------------- /Chapter16/9_robot_api/screenCapture-2018-23-9-18-2-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Java-11-Cookbook-Second-Edition/cb981ae138551e7eb20dd9c1dee399e608d039e5/Chapter16/9_robot_api/screenCapture-2018-23-9-18-2-03.png -------------------------------------------------------------------------------- /Chapter16/9_robot_api/src/gui/module-info.java: -------------------------------------------------------------------------------- 1 | module gui{ 2 | requires javafx.controls; 3 | requires javafx.graphics; 4 | requires java.desktop; 5 | requires javafx.swing; 6 | exports com.packt; 7 | } --------------------------------------------------------------------------------