Book Image

Spring Boot and Angular

By : Devlin Basilan Duldulao, Seiji Ralph Villafranca
Book Image

Spring Boot and Angular

By: Devlin Basilan Duldulao, Seiji Ralph Villafranca

Overview of this book

Angular makes building applications with the web easy and Spring Boot helps get an application up and running using just a few lines of code and minimal configuration. This book provides insights into building full-stack apps using Angular and Spring Boot effectively to reduce overall development time and increase efficiency. You'll start by setting up your CI/CD pipeline and then build your web application’s backend guided by best practices. You'll then see how Spring Boot allows you to build applications faster and more efficiently by letting the Spring Framework and Spring Boot extension do the heavy lifting. The book demonstrates how to use Spring Data JPA and add its dependencies along with Postgres dependencies in the project to save or persist a user's data in a database for future use. As you advance, you'll see how to write tests and test a service using Mockito. Finally, you'll create a CI workflow or pipeline for a Spring Boot and Angular application to enable operations to deliver quality applications faster. By the end of this Spring Boot and Angular book, you'll be able to build a full-stack web application and deploy it through continuous integration and continuous deployment.
Table of Contents (24 chapters)
Part 1: Overview of Spring Boot and Angular Development
Part 2: Backend Development
Part 3: Frontend Development
Part 4: Deployment

What’s new in Java 17?

We have decided to discuss Java 17 in this book as this is the next long-term support (LTS) version of Java, meaning that this version will be maintained for a more extended period. It was released on September 14, 2021, and includes several new security and development features.

Let’s look at some of the new features that have been included, as well as some modifications that have been applied to Java 17.

Sealed classes

Sealed classes were in the second preview stage in Java 16. Let’s say, for example, that we have a class that we have created in our code. We can assume that this class can be extended with any subclasses in our application. Thus, by making our classes sealed, we can ensure that our class can’t be extended by subclasses. If we want to allow some subclasses to extend our class, we can use the permits keyword to identify the specific classes we want to grant permission to, as shown in the following example:

public sealed class Animal permits Cat, Dog, Horse

The foreign function and memory API

A new API was introduced for accessing and using code outside the Java runtime, which it did by applying foreign functions (code outside the JVM) and safely accessing foreign memory (memory not handled by the JVM). The API allows a Java application to call native libraries without the Java Native Interface (JNI).

The API aims to replace the JNI with a pure Java development model and better performance while accessing off-heap data and omitting insecure operations.

Foreign memory

One common problem in Java today is accessing off-heap data. Off-heap data is data that’s stored in memory outside the Java runtime. We can say that this is a third-party library. Accessing this data is very critical to performance in that Java garbage collectors work only on on-heap data, which lets them avoid the unpredictability of garbage collections. The following APIs are used to handle off-heap data:

  • The ByteBuffer API: This API allows you to create direct ByteBuffers in off-heap data so that data can be managed outside the Java runtime. However, the major drawback of ByteBuffer is that its maximum size is 2 GB and that it is not deallocated promptly, causing the application’s runtime performance to slow down.
  • The Sun.misc.Unsafe API: The Unsafe API exposes access operations that work on off-heap data. This API makes this process efficient since the Just-in-Time (JIT) compiler optimizes access operations. However, using the Unsafe API is discouraged as we are allowing access to any memory location.
  • The Foreign Function and Memory API: This API solves the dilemma of accessing the memory’s location and sacrificing runtime performance as it provides classes and interfaces where applications can do the following:
    • Allocate Foreign Memory
    • Manipulate and access foreign memory
    • Call Foreign Functions

Pattern matching with switch statements

Pattern matching is the idea of testing patterns and complicated expressions in switch statements. This new feature allows for more extensible and flexible usage of switch statements to accept complex expressions.

The Applet API

The Applet API is rarely used in Java as all browsers have removed support for Java browser plugins.

The experimental AOT and JIT compilers

The experimental Java-based ahead-of-time (AOT) and JIT compilers have been removed since their features have limited usage.

These are just some of the changes that have been applied to Java 17. Now, let’s learn about Angular, one of the top JavaScript frameworks today, and the advantages of using the Angular framework to develop your frontend.