Title Page....2
Copyright Page....3
Dedication....4
About the Authors....5
About the Reviewers....6
Table of Contents....13
1. Hello Java....21
Introduction....21
Structure....21
Objectives....22
Requirements....22
Setting up a project....23
Hello Java....25
Principals of OOP....28
Encapsulation....29
Inheritance....36
Polymorphism....39
Built-in types....41
Arrays....43
Generics and Erasure....44
Debugging....48
Debugging Java....49
Conclusion....50
Points to remember....50
Multiple choice questions....51
Answers....52
2. OOP Patterns....54
Introduction....54
Structure....54
Objectives....55
Why OOP?....55
Basic Object-Oriented Design....56
Common patterns....57
Singleton....58
Factory....64
Builder....66
Adapter....70
Façade....72
Proxy....73
Observer....77
Command....79
Iterator....81
Immutability....83
Functional programming....85
Conclusion....87
Points to remember....88
Multiple choice questions....88
Answers....89
3. 8 to 21 to GraalVM....91
Introduction....91
Structure....92
Objectives....93
Java 8—the baseline....93
Lambda expressions....94
Method references....95
Default methods....96
Streams....97
Annotation changes....97
Method parameters reflection....98
New date and time APIs....98
VM changes....99
Modules AKA Jigsaw (Java 9)....100
Shenandoah (Java 12)....101
Not your fathers stop the world mark sweep....102
Generational garbage collection....102
Concurrent versus parallel garbage collector....102
Serial collector....103
Parallel collector or throughput collector....103
G1 Garbage Collector....104
Z Garbage Collector (ZGC)....104
Shenandoah....105
Microbenchmark Suite (Java 12)....105
Virtual Threads—Loom (Java 21)....108
Loom....110
Deprecation of finalization (Java 9)....113
UTF-8 by default (Java 18)....114
Language changes....115
Try with resources....115
Private methods in interfaces (Java 9)....116
var keyword (Java 10)....116
Switch expression (Java 14)....116
Sealed classes (Java 17)....119
Pattern-matching instanceof (Java 16)....120
Text blocks (Java 15)....120
Records (Java 16)....122
Record patterns (Java 19 preview)....122
String templates (Java 21 preview)....122
Unnamed patterns and variables (Java 21 preview)....123
APIs....124
HttpClient (Java 11)....124
Foreign function and memory API—Panama (Java 19)....125
Structured concurrency (Java 19)....126
Serialization filtering (Java 9)....127
Scoped values (Java 20)....128
Sequenced collection (Java 21)....129
Future....130
GraalVM....130
Valhalla....131
Conclusion....133
Points to remember....133
Multiple choice questions....133
Answers....134
4. Modern Threading....136
Introduction....136
Structure....136
Objectives....137
History....137
Concepts....139
Thread safety....140
Mutex (Lock)....141
Wait and notify (monitor)....143
Deadlock....146
Race conditions....147
Thread pools....148
Executors....148
Locks....150
Synchronizers....161
Atomic....164
Futures....165
Collections and queues....166
Conclusion....168
Points to remember....169
Multiple choice questions....169
Answers....170
5. It’s Springtime in Java....172
Introduction....172
Structure....172
Objectives....173
History and origin....173
Inversion of Control, Dependency Injection, and Aspect Oriented Programming....174
Hello Spring Boot....178
A REST API....184
Spring MVC and Thymeleaf....188
SQL and JDBC....200
SQL basics....200
Java Database Connectivity....202
Java Persistence Architecture....206
Error handling....212
Conclusion....215
Points to remember....215
Multiple choice questions....216
Answers....217
6. Testing and CI....219
Introduction....219
Structure....219
Objectives....220
Testing theory....220
JUnit....222
Mockito....225
Performance matters....227
What should we mock?....228
Test Driven Development....228
The problem with TDD....229
Continuous Integration....230
Continuous Integration tools....231
Cloud versus on premise....232
Agent statefullness....233
GitHub Actions....234
Branch protection....240
Linting....242
Conclusion....249
Points to remember....249
Multiple choice questions....250
Answers....251
7. Docker, Kubernetes, and Spring Native....253
Introduction....253
Structure....253
Objectives....254
Containers....254
Docker....255
Orchestration....258
Kubernetes (k8s)....259
The easy way—Skaffold....264
Infrastructure as Code (IaC)....271
Spring Native....273
Getting started with Spring Native....275
Cloud Native....278
Alternatives to Spring Native....279
Conclusion....281
Points to remember....281
Multiple choice questions....282
Answers....283
8. Microservices....285
Introduction....285
Structure....285
Objectives....286
Microservices versus small Monoliths....286
Service mesh....289
Authentication and authorization....292
Eventual consistency....298
Messaging....304
RabbitMQ....306
Apache Kafka....306
Spring cloud stream....307
Publish subscribe and point to point....308
Monolith first....313
Modular Monolith....315
Modulith....316
Other modules....318
The benefit....318
Conclusion....319
Points to remember....319
Multiple choice questions....319
Answers....320
9. Serverless....322
Introduction....322
Structure....322
Objectives....323
What is serverless....323
Using AWS Lambda....324
GraalVM and Monolith serverless....332
The cloud ecosystem....336
Conclusion....337
Points to remember....338
Multiple choice questions....338
Answers....339
10. Monitoring and Observability....341
Introduction....341
Structure....342
Objectives....342
What is monitoring?....342
Pillars of observability....344
The three pillars of observability....345
What makes a system observable?....346
Prometheus....348
Grafana....350
Micrometer....351
Actuator....353
Enabling and configuring Spring Boot actuator....354
Exposing custom information via Spring Boot actuator....355
Developer observability....357
Injecting logs....358
Snapshots/captures and non-breaking breakpoints....360
PII reduction and blocklists....361
Conclusion....362
Points to remember....362
Multiple choice questions....363
Answers....363
Index....365
Are you still using Java in the same old way? Java 21 has evolved into a dynamic and concise language with a vibrant and rich ecosystem. If you're seeking to expand your knowledge of modern Java programming, this book is the ideal resource for you.
This practical book offers valuable guidance on effectively utilizing the latest syntax enhancements in order to write code that is both streamlined and easy to understand. It not only provides detailed insights into the inner workings of the Java virtual machine (JVM), but also equips you with the knowledge necessary to excel in building scalable and resilient applications using a variety of powerful techniques such as Spring Boot, Spring Native, GraalVM, and other innovative methodologies. Furthermore, the book assists you in navigating the complexities of testing and packaging, helping you comprehend and navigate intricate processes. It also introduces you to cutting-edge deployment methodologies that leverage Docker and Kubernetes, ensuring that you stay up to date with the most recent advancements in software development and deployment practices.
By the time you finish reading this book, you will have upgraded your Java programming techniques and gained the ability to fully exploit the latest and greatest advancements in the language.
This book is suitable for individuals who are new to Java and have little to no experience but possess a basic understanding of the syntax. Additionally, it provides valuable insights for developers who may have not utilized Java in a significant timeframe.