Home Programming Jakarta EE Cookbook - Second Edition

Jakarta EE Cookbook - Second Edition

By Elder Moraes
books-svg-icon Book
eBook $26.99 $17.99
Print $38.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $26.99 $17.99
Print $38.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Server-Side Development
About this book
Jakarta EE is widely used around the world for developing enterprise applications for a variety of domains. With this book, Java professionals will be able to enhance their skills to deliver powerful enterprise solutions using practical recipes. This second edition of the Jakarta EE Cookbook takes you through the improvements introduced in its latest version and helps you get hands-on with its significant APIs and features used for server-side development. You'll use Jakarta EE for creating RESTful web services and web applications with the JAX-RS, JSON-P, and JSON-B APIs and learn how you can improve the security of your enterprise solutions. Not only will you learn how to use the most important servers on the market, but you'll also learn to make the best of what they have to offer for your project. From an architectural point of view, this Jakarta book covers microservices, cloud computing, and containers. It allows you to explore all the tools for building reactive applications using Jakarta EE and core Java features such as lambdas. Finally, you'll discover how professionals can improve their projects by engaging with and contributing to the community. By the end of this book, you'll have become proficient in developing and deploying enterprise applications using Jakarta EE.
Publication date:
May 2020
Publisher
Packt
Pages
380
ISBN
9781838642884

 

Server-Side Development

Jakarta EE is typically used for server-side development. Most of its APIs are powerful and used for server-side processing and management.

This chapter will provide you with some common and useful scenarios that you may face as a Jakarta EE developer and will show you how to deal with them.

In this chapter, we will cover the following recipes:

  • Using Jakarta CDI to inject context and dependencies
  • Using Jakarta Bean Validation for data validation
  • Using Jakarta Servlet for request and response management
  • Using Server Push to make objects available beforehand
  • Using EJB and JTA for transaction management
  • Using EJB to deal with concurrency
  • Using JPA for smart data persistence
  • Using EJB and JPA for data caching
  • Using Jakarta Batch processing

Let's get started!

 

Using Jakarta CDI to inject context and dependencies

Jakarta Contexts and Dependency Injection (CDI) is one of the most important APIs under the Jakarta EE umbrella. Introduced in Java EE 6, it now has a big influence over many other APIs.

In the recipe, you will learn how to use Jakarta CDI in a couple of different ways and situations.

Getting ready

First, let's add the required dependency:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

...
 

Using Jakarta Bean Validation for data validation

You can use Bean Validation to constrain your data in many different ways. In this recipe, we are going to use it to validate a JSF form so that we can validate it as soon as the user tries to submit it and avoid any invalid data right away.

Getting ready

First, we need to add our dependencies:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

You need...

 

Using Jakarta Servlet for request and response management

Jakarta Servlet was created even before Jakarta EE existed actually, before J2EE existed! It became part of EE in J2EE 1.2 (Servlet 2.2) in 1999.

This is a powerful tool that's used to deal with request/response contexts. This recipe will show you an example of how to do this.

Getting ready

Let's add our dependencies:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

...
 

Using Server Push to make objects available beforehand

One of the most important new features of Jakarta Servlet 4 is its HTTP/2.0 support. It brings another cool and reliable feature Server Push.

This recipe will show you how to use Server Push in a filter and push the resources needed in every request that we want.

Getting ready

First, we need to add the required dependencies:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

...
 

Using EJB and JTA for transaction management

Jakarta Transaction (formerly JTA) is an API that enables distributed transactions over the Jakarta EE environment. It is most powerful when you delegate transaction management to the server.

This recipe will show you how to do this!

Getting ready

First, add the required dependencies:

        <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version...
 

Using EJB to deal with concurrency

Concurrency management is one of the biggest advantages supplied by a Jakarta EE server. You can rely on a ready environment to deal with this tricky topic.

This recipe will show you how to set up your own Jakarta Enterprise Beans (formerly EJBs) to use it!

Getting ready

To get ready, you simply need to add a Jakarta EE dependency to your project:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

...
 

Using JPA for smart data persistence

Jakarta Persistence (formerly JPA) is a specification that describes an interface for managing relational databases using Jakarta EE.

It eases data manipulation and reduces a lot of the code written for it, especially if you are used to the SQL American National Standards Institute (ANSI).

This recipe will show you how to use it to persist your data.

Getting ready

First, let's add the required dependencies:

        <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId...
 

Using EJB and JPA for data caching

Knowing how to build a simple and local cache for your application is an important skill. It may have a big impact on some data access performance and is quite easy to do.

This recipe will show you how to do this.

Getting ready

Simply add a Jakarta EE dependency to your project:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

How to do it...

You need to perform the following steps...

 

Using Jakarta Batch processing

Running background tasks is a useful and important skill in an enterprise context.

You could use it to process data in bulk or just to separate it from the UI processes. This recipe will show you how to do this.

Getting ready

Let's add our dependencies:

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
...
About the Author
  • Elder Moraes

    Elder Moraes helps Jakarta EE developers build and deliver secure, fast, and available applications so that they are able to work on great projects. He is passionate about content sharing; he does it by speaking at international events, blogging, and writing articles. He has been working with Java since 2002 and has developed applications for different industries. As a board member at SouJava, he led the Java EE 8 - The Next Frontier initiative, interviewing some world-class Java EE experts

    Browse publications by this author
Latest Reviews (1 reviews total)
Very useful recipts that can be applied in my personal and professional opportunity
Jakarta EE Cookbook - Second Edition
Unlock this book and the full library FREE for 7 days
Start now