Java 11 Cookbook
eBook - ePub
No longer available

Java 11 Cookbook

A definitive guide to learning the key concepts of modern application development, 2nd Edition

  1. 802 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub
No longer available

Java 11 Cookbook

A definitive guide to learning the key concepts of modern application development, 2nd Edition

About this book

Solutions for modular, functional, reactive, GUI, network, and multithreaded programming

Key Features

  • Explore the latest features of Java 11 to implement efficient and reliable code
  • Develop memory-efficient applications, understanding new garbage collection in Java 11
  • Create restful webservices and microservices with Spring boot 2 and Docker

Book Description

For more than three decades, Java has been on the forefront of developing robust software that has helped versatile businesses meet their requirements. Being one of the most widely used programming languages in history, it's imperative for Java developers to discover effective ways of using it in order to take full advantage of the power of the latest Java features. Java 11 Cookbook offers a range of software development solutions with simple and straightforward Java 11 code examples to help you build a modern software system.

Starting with the installation of Java, each recipe addresses various problem by explaining the solution and offering insights into how it works. You'll explore the new features added to Java 11 that will make your application modular, secure, and fast. The book contains recipes on functional programming, GUI programming, concurrent programming, and database programming in Java. You'll also be taken through the new features introduced in JDK 18.3 and 18.9.

By the end of this book, you'll be equipped with the skills required to write robust, scalable, and optimal Java code effectively.

What you will learn

  • Set up JDK and understand what's new in the JDK 11 installation
  • Implement object-oriented designs using classes and interfaces
  • Manage operating system processes
  • Create a modular application with clear dependencies
  • Build graphical user interfaces using JavaFX
  • Use the new HTTP Client API
  • Explore the new diagnostic features in Java 11
  • Discover how to use the new JShell REPL tool

Who this book is for

The book is for intermediate-to-advanced Java programmers who want to make their applications fast, secure, and scalable.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Java 11 Cookbook by Nick Samoylov, Mohamed Sanaulla in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

Database Programming

This chapter covers both basic and commonly used interactions between a Java application and a database (DB), right from connecting to the DB and performing CRUD operations to creating transactions, storing procedures, and working with large objects (LOBs). We will be covering the following recipes:
  • Connecting to a database using JDBC
  • Setting up the tables required for DB interactions
  • Performing CRUD operations using JDBC
  • Using the Hikari Connection Pool (HikariCP)
  • Using prepared statements
  • Using transactions
  • Working with large objects
  • Executing stored procedures
  • Using batch operations for a large set of data
  • Using MyBatis for CRUD operations
  • Using the Java Persistence API and Hibernate

Introduction

It is difficult to imagine a complex software application that does not use some kind of structured and accessible data storage called a database. This is why any modern language implementation includes a framework that allows you to access the DB and create, read, update, and delete (CRUD) data in it. In Java, the Java Database Connectivity (JDBC) API provides access to any data source, from relational databases to spreadsheets and flat files.
Based on this access, an application can manipulate data in the database directly, using database language (SQL, for example), or indirectly, using an Object-Relational Mapping (ORM) framework, which allows for the mapping of objects in memory to the tables in the database. The Java Persistence API (JPA) is the ORM specification for Java. When an ORM framework is used, the CRUD operations on the mapped Java objects are translated into the database language automatically. The list of the most popular ORM frameworks includes Apache Cayenne, Apache OpenJPA, EclipseLink, jOOQ, MyBatis, and Hibernate, to name a few.
The java.sql and javax.sql packages that compose the JDBC API are included in the Java Platform Standard Edition (Java SE). The java.sql package provides the API for accessing and processing data stored in a data source (usually a relational database). The javax.sql package provides the API for server-side data source access and processing. Specifically, it provides the DataSource interface for establishing a connection with a database, connection and statement pooling, distributed transactions, and rowsets. The javax.persistence package that contains interfaces that are compliant with JPA is not included in Java SE and has to be added as a dependency to the Maven configuration file pom.xml. The specific JPA implementation—the preferred ORM framework—has to be included as a Maven dependency too. We will discuss the usage of JDBC, JPA, and two ORM frameworks—Hibernate and MyBatis—in the recipes of this chapter.
To actually connect DataSource to a physical database, you also need a database-specific driver (provided by a database vendor, such as MySQL, Oracle, PostgreSQL, or SQL server database, for example). It may be written in Java or in a mixture of Java and Java Native Interface (JNI) native methods. This driver implements the JDBC API.
Working with a database involves eight steps:
  1. Installing the database by following the vendor instructions.
  2. Adding the dependency on a .jar to the application with the database-specific driver.
  3. Creating a user, database, and database schema—tables, views, stored procedures, and so on.
  4. Connecting to the database from the application.
  5. Constructing an SQL statement directly using JDBC or indirectly using JPA.
  1. Executing the SQL statement directly using JDBC or committing data changes using JPA.
  2. Using the result of the execution.
  3. Closing the database connection and other resources.
Steps 1 –3 are done only once at the database setup stage, before the application is run.
Steps 4 – 8 are performed by the application repeatedly, as needed.
Steps 5 – 7 can be repeated multiple times with the same database connection.

Connecting to a database using JDBC

In this recipe, you will learn how to connect to a database.

How to do it...

  1. Select the database you would like to work with. There are good commercial databases and good open source databases. The only thing we are going to assume is that the database of your choice supports Structured Query Language (SQL), which is a standardized language that allows you to perform CRUD operations on a database. In our recipes, we will use the standard SQL and avoid constructs and procedures specific to a particular database type.
  2. If the database is not installed yet, follow the vendor instructions and install it. Then, download the database driver. The most popu...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Installation and a Sneak Peek into Java 11
  7. Fast Track to OOP - Classes and Interfaces
  8. Modular Programming
  9. Going Functional
  10. Streams and Pipelines
  11. Database Programming
  12. Concurrent and Multithreaded Programming
  13. Better Management of the OS Process
  14. RESTful Web Services Using Spring Boot
  15. Networking
  16. Memory Management and Debugging
  17. The Read-Evaluate-Print Loop (REPL) Using JShell
  18. Working with New Date and Time APIs
  19. Testing
  20. The New Way of Coding with Java 10 and Java 11
  21. GUI Programming Using JavaFX
  22. Other Books You May Enjoy