Statistics
29
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-01-16

AuthorDavi Vieira

Java continues to be a key technology for building powerful applications in today’s fast-changing tech world. This book helps you connect theory with practice, teaching you the skills to create real-world Java projects. With a clear learning path, you will learn the tools and techniques needed to tackle complex software development challenges with confidence. This book, inspired by real-world Java projects, starts with Java fundamentals, covering core APIs, modern features, database handling, and automated testing. It explores frameworks like Spring Boot, Quarkus, and Jakarta EE for enterprise cloud-native applications. Employ container technologies like Docker and Kubernetes for scalable deployments. To tackle production challenges, the book will look deeply into monitoring and observability, helping developers understand application performance under unexpected conditions. It concludes with maintainability issues, introducing architectural concepts like domain-driven design (DDD), layered architecture, and hexagonal architecture, offering a roadmap for creating scalable and maintainable Java applications. By the end of this book, you will feel confident as a Java developer, ready to handle real-world challenges and work on modern software projects. You will have a strong understanding of Java basics, modern tools, and best practices, preparing you for a successful career in Java development.

Tags
No tags
ISBN: 9365898978
Publisher: BPB Publications
Publish Year: 2025
Language: 英文
Pages: 378
File Format: PDF
File Size: 4.6 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
(This page has no text content)
Java Real World Projects A pragmatic guide for building modern Java applications Davi Vieira www.bpbonline.com
First Edition 2025 Copyright © BPB Publications, India ISBN: 978-93-65898-972 All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication, photocopy, recording, or by any electronic and mechanical means. LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s and publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but publisher cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners but BPB Publications cannot guarantee the accuracy of this information. www.bpbonline.com
Dedicated to Those who work late into the night and persist in their goals.
About the Author Davi Vieira is a software craftsman with a vested interest in the challenges large enterprises face in software design, development, and architecture. He has over ten years of experience constructing and maintaining complex, long- lasting, and mission-critical systems using object-oriented languages. Davi values the good lessons and the software development tradition left by others who came before him. Inspired by such software tradition, he develops and evolves his ideas. Davi started his career in technology by working as a Linux system administrator in the web hosting industry. After learning much about server task automation with shell scripting, he moved on to the banking industry, where he fixed bugs in legacy Java systems. Working with such legacy systems enabled Davi to face exciting challenges in a telecommunications organization, where he played a crucial role in helping the company adopt cloud-native development practices. Eager to learn and make a lasting impact, Davi works currently as a tech lead for an enterprise software company.
About the Reviewers ❖ Ron Veen is a seasoned software engineer with over 20 years of experience in the Java ecosystem. From mainframes to microservices, he’s seen it all. His passion for software engineering and architecture drives his work. A certified Java expert (OCP and SCBCD/OCPBCD), Ron is proficient in a wide range of frameworks and libraries, from Apache to ZK. He is also keen on exploring alternative JVM languages like Kotlin. As a special agent and senior developer at Team Rockstars IT, Ron shares his knowledge as an international conference speaker and via his written works. He is the author of books on ‘Java Cloud-native migrations with Jakarta EE’ and ‘virtual threads, structured concurrency, and scoped values’. ❖ Stan Komar (Stanislaw Kazimierz Komar) is a business owner focused on industrial automation and systems integration, using either Rockwell Automation, Schnieder, Siemens or Mitsubishi Tools. He has been actively programming since 1973 and is going strong. Although he should be retired, he enjoys the projects he works on so much that “Retirement can Wait.” There is just so much change in the programming world that keeping up-to-date is very challenging. At 69 years young, he is an avid tennis player.
Acknowledgement I vividly remember my brother Bruno Pinheiro de Oliveira exploring the computer, discovering things on the internet, and downloading Linux on a dial-up connection until late at night when I was a kid. My passion for technology started there. Thank you, my brother, for instilling such a passion in me. I am grateful for my parents, Davi and Rosimar, who always believed in and supported my dreams, and also my wife, Eloise, and my son, Davi, for giving me a strong why when things got tough. My Java journey started when learning the programming language was more about keeping my job during significant professional changes than anything else. I am still on this journey and want to acknowledge the people who contributed to my learning by allowing me to get along with them. My first exposure to enterprise software at HSBC Global Technology was essential to lay the foundation that would culminate in the writing of this book. I am forever grateful for working with remarkable folks like Ana Carolina Moises de Souza, Renan Augusto da Silva, Caio Cesar Ferreira, Marco Aurélio Scheid, Ricardo André Pikussa, Carlos Bochnia, Emilio Fernandes, Adenir Rodrigues Filho, Alejandro Andrade, Jeferson Rodrigues (in memoriam), and Luiz Hauth from which will never forget his leadership lessons. I cannot forget to mention Filipe Negrello for a brief, though intense, working relationship that led me to start working at
Telefónica, where I had the chance to meet brilliant minds like Wilson Bissi, Lucas Maldaner, Mauricio Orozimbro de Souza, Raoni Gabriel, Roberto Silva Ramos Junior, Leonardo Henrique Pereira, Tiago Silvestrini, Renan Fabrão, Wagner Fernando Costa, Adriano Wierzbicki, Rodrigo Ribeiro, Nelmar Alvarenga, Hamilton Santos Junior, Jefferson Lira, Wagner Sales (in memoriam), Newton Dore, Giuliano Recco, Luiz Guilherme Mattos, Elizabete Yanase Hirabara Halas, André Santos, Arthur Gomes Junior, Renan Pazini, Thiago Alberto Gil, and Julio Cesar Trincaus. Also, I want to thank Fagner da Silva and Paulo Jorge Lagranha for making a lasting impact on my career and Java journey that lasts to this day. I am immensely grateful for working with such amazing people who influenced me profoundly and shaped my character for my next challenge at SAP. While working at SAP, I had the chance to collaborate on many cool projects that directly influenced the ideas I shared in this book. That is why I want thank Victor Fonseca, Vera Hillmann, Angelina Lange, Nils Faupel, Rafał Sokalski, Shumail Arshad, Saad Ali Jan, Kaiser Anwar Shad, Bruno Fracalossi Ferreira, Charne Elizabeth Pearson, Anna Kovtun, Rachel Falk, Arkadii Drovosekov, Reshmi Muhkerjeee, Anna Szarek, Rima Augustine, Babatunde Mustapha, Ahmed Alsharkawy, Taniya Vincent, and Torge Harbig. Thanks also to Vladimir Afanasenkov for being such a solid professional reference for me. Last but not least, I want to thank Scott Wierschem, Bruno Souza, Elder Moraes, and Otavio Santana for every advice that influenced my thinking and motivated me to keep moving forward.
Preface After so many years since its first release, Java remains as relevant as ever by powering the most critical applications in enterprises of all sizes. It is not uncommon to see Java applications still running ten, twenty, or more years ago, which serves as a testament to Java’s robust and reliable nature. On the other side of the coin, Java continues to be the language of choice for many new projects that have the luxury of choosing from a set of high-quality frameworks like Spring Boot, Quarkus, or Jakarta EE, to name a few, that foster innovation and keep the Java language fresh to tackle the challenges of modern software development in the age of cloud and artificial intelligence. There has never been a better time to be part of such an exciting technological ecosystem, which offers endless opportunities to impact other people’s lives through software. Based on this landscape of opportunities and innovations, this book was written for those who decide to face the complexities, ambiguities, and hardships that may derive from any serious Java project. It is not meant to be a comprehensive guide for the Java programming language; instead, it takes a pragmatic approach in emphasizing, from the author’s perspective, the relevant Java features and anything related to producing production-ready software. Starting with exploring Java fundamentals, this book revisits core Java API components used to efficiently handle data structures, files, exceptions, logs, and other essential elements found in most enterprise Java applications. It also
examines how modern Java features such as sealed classes, pattern matching, record patterns, and virtual threads can be used to create software systems that extract the best of what Java can provide. This book presents techniques for efficiently handling relational databases by tapping into the Java Database Connectivity (JDBC) and Jakarta Persistence APIs (JPA), thereby providing a solid Java data handling foundation. Still, in the context of Java fundamentals, it explores how to increase overall code quality by employing unit and integration tests. After covering the Java Fundamentals, this book explores how reliable software development frameworks such as Spring Boot, Quarkus, and Jakarta EE can be used to develop applications based on developer-friendly and productivity principles. These frameworks empower the Java developer by enabling him to use cutting-edge technology and industry standards that are the basis for most critical back-end applications. With an eye on the everyday challenge of keeping Java applications running reliably in production, this book describes essential monitoring and observability techniques that help the Java developer better understand how well its application is behaving under different and quite often unexpected circumstances, putting the developer in a more pro-active than reactive position when dealing with bottlenecks, scalability and any other issue that can represent a risk for the application availability. It concludes with an exploration of how different software architecture ideas, such as domain-driven design (DDD), layered architecture, and hexagonal architecture, can play crucial roles in developing change-tolerable and maintainable applications that not only deliver what the customer wants but also establish solid foundations that
enable developers to gracefully introduce code changes with reduced refactoring efforts. Chapter 1: Revisiting the Java API - This chapter revisits essential core Java APIs commonly seen in real-world projects. It starts by exploring the Collections API’s data structures, showing the possible ways to handle data as objects in Java systems. Considering how often files must be dealt with, this chapter shows how to manipulate files using the NIO2. A closer examination of exceptions, followed by the Logging API, provides a solid foundation for helpful error handling and enhanced logging management. As most Java applications somehow need to deal with date and time, the Data-Time API is also explored. Closing the chapter, functional programming features such as streams and lambdas are covered to show how to write more efficient and concise Java code. Chapter 2: Exploring Modern Java Features - Java is constantly changing. Therefore, it is essential to keep up to date with its new features. This chapter looks into modern Java capabilities developers can leverage to build robust applications with sophisticated language features. It starts by explaining how to use sealed classes to increase inheritance control. It presents an intuitive way of matching Java types with pattern matching and using record patterns to extract data from matched types. Finally, it shows how to simplify the development of concurrent applications with virtual threads. Chapter 3: Handling Relational Databases with Java - The ability to efficiently communicate with databases is a crucial characteristic of Java applications requiring persistence. Based on this premise, this chapter explores the Java Database Connectivity (JDBC) API, a fundamental Java component for handling relational databases. To enable developers to handle database entities
as Java objects, it distills the main features of the Jakarta Persistence. The chapter finishes by examining local development approaches with container-based and in- memory databases for Java. Chapter 4: Preventing Unexpected Behaviors with Tests - Automated tests help to prevent code changes from breaking existing system behaviors. To help developers with such an outcome, this chapter overviews two automated test approaches: unit and integration testing. It explores the reliable and widely used test framework JUnit 5. Finally, it describes how to use Testcontainers to implement reliable integration tests that rely on real systems as test dependencies. Chapter 5: Building Production-Grade Systems with Spring Boot - Regarded as one of the most well-used Java frameworks, Spring Boot has withstood the test of time. So, this chapter explores the fundamental Spring components present in Spring Boot. Such fundamental knowledge leads to an analysis of how to bootstrap a new Spring Boot project and implement a CRUD application with major Spring Boot features. Chapter 6: Improving Developer Experience with Quarkus - In the age of cloud, Quarkus has arisen as a cloud-first Java development framework with the promise of delivering a developer-friendly framework that empowers developers to create cloud-native applications based on the best industry standards and technology. This chapter starts assessing the benefits Quarkus provides, shifting quickly to an explanation that details how to kickstart a new Quarkus project. It then shows how to use well-known Quarkus features to develop a CRUD application, including support for native compilation. Chapter 7: Building Enterprise Applications with Jakarta EE and MicroProfile - Accumulating decades of
changes and improvements, the Jakarta EE (formerly Java EE and J2EE) framework still plays a major role in enterprise software development. Relying on Jakarta EE, there is also MicroProfile, a lean framework to develop cloud-native microservices. Focusing on these two frameworks, this chapter starts with an overview of the Jakarta EE development model and its specifications. Then, it jumps to hands-on practice by showing how to start a new Jakarta EE project and develop an enterprise application. Finally, it shows how to create microservices using MicroProfile. Chapter 8: Running Your Application in Cloud-Native Environments - Any serious Java developer must be able to make Java applications extract everything they can and perform well inside cloud environments. That is why this chapter explores cloud technologies, starting with container technologies, including Docker and Kubernetes. It explains how Java applications developed using frameworks like Spring Boot, Quarkus, and Jakarta EE can be properly dockerized to run in containers. Finally, it describes deploying such applications into a Kubernetes cluster. Chapter 9: Learning Monitoring and Observability Fundamentals - Understanding how a Java application behaves in production while being accessed by many users is critical to ensuring the business health of any organization. Considering this concern, this chapter explores what monitoring and observability mean and why they are crucial for production-grade Java systems. It then shows how to implement distributed tracing with Spring Boot and OpenTelemetry. Also, it explains how to handle logs using Elasticsearch, Fluentd, and Kibana. Chapter 10: Implementing Application Metrics with Micrometer - Metrics are essential to answer whether a Java application behaves as expected. Micrometer is a key technology that enables developers to implement metrics
that answer those questions. This chapter explains how to use a Micrometer to provide metrics in a Spring Boot application. Chapter 11: Creating Useful Dashboards with Prometheus and Grafana - Visualizing important information regarding an application’s behavior through dashboards can prevent or considerably speed up the resolution of incidents in Java applications. Based on such concern, this chapter examines how to capture application metrics using Prometheus. It then covers the integration between Prometheus and Grafana, two essential monitoring tools. Finally, it shows how to create helpful Grafana dashboards with metrics generated by a Java application and use Alertmanager to trigger alerts based on such metrics. Chapter 12: Solving problems with Domain-driven Design - Based on the premise that the application code can serve as an accurate representation of a problem domain, Domain-driven Design (DDD) proposes a development approach that puts the problem domain as the driving factor that dictates the system’s architecture, resulting in better maintainable software. Considering such maintainability benefits, this chapter starts with a DDD introduction, followed by an analysis of essential ideas like value objects, entities, and specifications. The chapter closes by exploring how to test the domain model produced by a DDD application. Chapter 13: Fast Application Development with Layered Architecture - Enterprises of all sorts rely on back-end Java applications to support their business. The ability to fast deliver such applications is fundamental in a competitive environment. Layered architecture emerged organically among the developer community due to its straightforward approach to organizing application
responsibilities into layers. In order to show the layered architecture benefits, this chapter starts with an analysis of the major ideas that comprise such architecture, followed by a closer look into applying layered architecture concepts in the development of a data layer for handling database access, a service layer for providing business rules, and an API layer for exposing system behaviors. Chapter 14: Building Applications with Hexagonal Architecture - The pace at which technologies change in software systems has increased considerably over the last years, creating challenges for those who want to tap into the latest cutting-edge innovations to build the best software possible. However, incorporating new technologies into existing working software may be challenging. That is where hexagonal architecture comes in as a solution to build change-tolerable applications that can receive significant technological changes without major refactoring efforts. With such advantage in mind, this chapter introduces the hexagonal architecture ideas, followed by hands-on guidance explaining the development of a hexagonal system based on the domain, application, and framework hexagons.
Code Bundle and Coloured Images Please follow the link to download the Code Bundle and the Coloured Images of the book: https://rebrand.ly/bdae2b The code bundle for the book is also hosted on GitHub at https://github.com/bpbpublications/Java-Real-World- Projects. In case there’s an update to the code, it will be updated on the existing GitHub repository. We have code bundles from our rich catalogue of books and videos available at https://github.com/bpbpublications. Check them out! Errata We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors, if any, that may have occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at : errata@bpbonline.com Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family.
Did you know that BPB offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.bpbonline.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at : business@bpbonline.com for more details. At www.bpbonline.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on BPB books and eBooks. Piracy If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at business@bpbonline.com with a link to the material. If you are interested in becoming an author If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit www.bpbonline.com. We have worked with thousands of developers and tech professionals, just like you, to help them share their insights with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Reviews Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions. We at BPB can understand what you think about our products, and our authors can see your feedback on their book. Thank you! For more information about BPB, please visit www.bpbonline.com. Join our book’s Discord space Join the book’s Discord Workspace for Latest updates, Offers, Tech happenings around the world, New Release and Sessions with the Authors: https://discord.bpbonline.com
(This page has no text content)
Table of Contents 1. Revisiting the Java API Introduction Structure Objectives Handling data structures with collections Creating ordered object collections with lists Providing non-duplicate collections with a set Using maps to create key-value data structures Using the NIO2 to manipulate files Creating paths Handling files and directories Error handling with exceptions Checked exceptions Unchecked exceptions Final block and try-with-resources Creating custom exceptions Improving application maintenance with the Logging API Log handlers, levels, and formats Exploring the Date-Time APIs LocalDate LocalTime LocalDateTime ZoneDateTime