Learn how to not have to implement getters, setters, and other methods for your Java applications by only using a few annotations.
Developing in Java can sometimes feel a little bit verbose. As programmers, we are always eager to write more code but wanting to do less at the same time.
Project Lombok is an open-source library that helps you write less code in a few areas. …
Reactive forms are an alternative to creating forms in Angular. Most of the heavy lifting for creating reactive forms happens in the component class instead of the template (HTML file).
One of the big benefits of using reactive forms is that it makes testing easier. The reason for this is that all the code related to your form lives in the component class. Given this, you don’t need to access the template on your tests to test your form. Instead, you can simply write a unit test.
The first step to implement a reactive form will be to import
ReactiveFormsModule to your application’s module. …
The decorator design pattern is a software design pattern that helps you add responsibilities to an object at runtime. This pattern is considered to be a structural design pattern. This type of pattern focuses on the relationships between classes and how they can help solve specific problems.
The Gang of Four, in their book Design Patterns: Elements of Reusable Object-Oriented Software, defined the intent of decorator pattern like this:
Intent: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
One of the key characteristics of this design pattern is that it follows the Single Responsibility Principle (SRP). This is because each “decoration” you add to an object, will be encapsulated within a class. This class’s responsibility will be to handle everything related to adding that decoration to that object. …
Angular applications by default rely on the browser to compile all the code. Even though this is the behavior, there is a way to change this. You can change your application to compile on a server instead of the client’s browser.
This discussion comes down to client-side rendering (CSR) vs server-side rendering (SSR). In this article, I’ll be going over what SSR and CSR are, their pros and cons, and how to convert your application to do SSR.
In simple terms, CSR relies on the client’s browser to compile the code. On the other hand, SSR relies on a server to compile the code which then gets returned already compiled to the client. …
You might be familiar with CI tools such as TeamCity, Jenkins, Concourse, Travis CI to mention a few. Well, this time we’ve got a new neighbor in town.
This new neighbor offers new capabilities to automating your workflows: GitHub Actions.
GitHub Actions provides different ways to automate development tasks. Some of the things you could do are:
These are just a few ideas, but as you can see, possibilities are endless…. …
You might have heard before about the Singleton Design Pattern. It could have been in a book, online course, or in school. Back in the day when I first heard about it, I thought, why would I need to use this pattern? What I wish my professor could have told me was a real-world example of why it is needed.
Several years after that course, I had a good lesson on when to use it and why it is important. Let’s go over why this pattern is so important based on that time where everything went bad for me.
A few years ago, I was working on a side project and it started receiving an unusual amount of traffic. Our user-facing webpage went down and no one could access it. I received a call asking what went was going on. …
If you were to have to do the sum of integer values inside a stream of objects, you will consider a few options such as leveraging the
reduce stream function. Or… the most known one: loop through all the objects and keep a variable with the running sum of values
Stream API offers a very simple way of calculating sum, finding min or max, and calculating the average for a stream of objects.
Depending on your numeric data type (
long) you might need to use
Sometimes conversions between data structures might become repetitive or prone to errors. If you are working with streams in Java, you might need to grab a list, convert it to a stream, and map it to another data structure.
There is a very easy way to do these types of conversions thanks to the
Collectors APIs from Java. In this article, I’ll be going over different ways in which you can convert streams to other data structures.
A few of the data structure conversions I’ll be covering will be:
MVC handler interceptors let you execute code before and after processing your HTTP requests. Let’s go over some scenarios where the pre and post-processing on handler interceptors could help with:
1 — Capture metrics for your HTTP requests processing times
2 — Add logs for your every one of your HTTP requests
3 — Validate routes contain the right authentication header
Let’s go first over the setup required for creating your own handler interceptor. …
The Stream API was introduced as of Java 8 and brought a very simple way to perform certain types of operations on your data. According to Java’s documentation, a stream is defined as
A sequence of elements supporting sequential and parallel aggregate operations
Some of the operations you’ll be able to perform with streams that we’ll cover in here are the following:
1 — Filter
2 — Map
3 — Count
4 — Reduce
5 — Verify if all elements in a stream match a criteria
6 — Verify if at least one element in a stream matches a criteria
7 — Verify none of the elements in a stream match a criteria