Book Image

Kotlin for Enterprise Applications using Java EE

By : Raghavendra Rao K
Book Image

Kotlin for Enterprise Applications using Java EE

By: Raghavendra Rao K

Overview of this book

Kotlin was developed with a view to solving programmers’ difficulties and operational challenges. This book guides you in making Kotlin and Java EE work in unison to build enterprise-grade applications. Together, they can be used to create services of any size with just a few lines of code and let you focus on the business logic. Kotlin for Enterprise Applications using Java EE begins with a brief tour of Kotlin and helps you understand what makes it a popular and reasonable choice of programming language for application development, followed by its incorporation in the Java EE platform. We will then learn how to build applications using the Java Persistence API (JPA) and Enterprise JavaBeans (EJB), as well as develop RESTful web services and MicroServices. As we work our way through the chapters, we’ll use various performance improvement and monitoring tools for your application and see how they optimize real-world applications. At each step along the way, we will see how easy it is to develop enterprise applications in Kotlin. By the end of this book, we will have learned design patterns and how to implement them using Kotlin.
Table of Contents (13 chapters)

What this book covers

The book starts with the fundamentals of Kotlin language and a brief about Java EE platform, then focuses on using Java EE with Kotlin. It also covers RESTful services, securing services and implementing Microservices. Lastly it covers Application monitoring,
Profiling and Design Patterns.

Chapter 1, Kotlin – a First look, we’ll be introducing you to the world of Kotlin. We learn the basics of Kotlin and take a quick dive into various features that the Kotlin language offers.

Chapter 2, Kotlin – The Game Changer, explains how Kotlin would be a game changer in terms of developing real-world, enterprise applications. We discuss where Kotlin scores over Java and why it is becoming increasingly popular. After addressing key practices, and the advantages it has, we'll be building a basic Kotlin project using IntelliJ IDEA and Eclipse. We then cover the Coroutines (a very lightweight thread) used for programming asynchronously. We will also learn about intermixing Java and Kotlin.

Chapter 3, An Overview of Java EE and Kotlin, gives a bird's eye view of the Java EE platform. We'll be introducing Kotlin in our Java EE applications. We discuss the challenges that Java EE needs to tackle to make Kotlin work in unison. The Kotlin plugins that will aid in the cause will be integrated into our Java EE applications as we begin our journey to build apps using Kotlin and embrace the new programming language. We also cover creating a web application using Servlets, and EJB with Kotlin.

As Kotlin is based on JVM, it is fully compatible with existing Java-based frameworks such as JSF.

Chapter 4, Kotlin with JSF and CDI, discusses how to make Kotlin work with JSF and dependency injection using CDI. We then discuss how we can use CDI to create domain events. We also cover interceptors and a use case where they can be applied. This chapter will be another significant step in our journey of developing Java EE applications using Kotlin.

Chapter 5, Kotlin with JPA and EJB, explains how to bootstrap JPA with Kotlin. We then move onto modeling JPA entities. We also discuss transaction management and handling exceptions in an application. Along the way, we'll integrate each of the preceding frameworks to build a real-world application.

Java EE 8 introduced JMS 2.0, which greatly simplified the development of applications involving messaging functionality.

Chapter 6, Enterprise Messaging with Kotlin, covers the development of messaging models using Kotlin and the Java Messaging Service (JMS). We will discuss messaging queues and topics. We will implement Point-to-point and Publish-Subscribe messaging models. We will also cover the acknowledging of messages and transactions.

Chapter 7, Developing RESTful Services with JAX-RS, discusses the concepts of REST specifications and examples of JAX-RS API. Furthermore, we'll be looking at Jersey—a popular implementation of JAX-RS API, while implementing them in web services using Kotlin.

Java EE 8 introduces a new security API that standardizes application security across all Java EE 8-compliant application servers. The new Java EE 8 API includes support for authentication mechanisms, allowing us to authenticate users in a standard way. Several authentication mechanisms are supported, such as basic HTTP authentication, client certificates, HTML forms, and more. We will discuss what the Security API is all about, along with developing a web application that implements the same using Kotlin in chapter 8.

Chapter 8, Securing Java EE Applications with Kotlin. It also covers implementation of the JSON Web Token (JWT) to secure the RESTful APIs.

The main purpose of a microservice architecture is to break down an application into smaller standalone components that are easier to handle, deploy, scale, and maintain in the long term.

Chapter 9, Implementing Microservices with Kotlin, examines ways to refactor monolith applications into microservices. We will implement microservices using Kotlin.

Chapter 10, Performance Monitoring and Logging, discusses how to find memory leaks. We'll be exploring the performance and monitoring tools used for enterprise applications. We'll look into garbage collection (GC), tuning the GC, and profiling.

Design patterns may be viewed as a structured approach to computer programming. A software design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

Chapter 11, Design Patterns with Kotlin, dives into the various design patterns. We will learn the different types of patterns, specifically among the creational, structural, and behavioral patterns, and implement them using Kotlin.