Category: java
-
How to Encrypt/Decrypt files and byte arrays in Java using AES-GCM
In this post, we will discuss how to encrypt and decrypt a file using the AES encryption algorithm in GCM mode. We will start by writing a file reader / writer to read and write files into byte arrays. Then we will attempt to encrypt and decrypt these byte arrays. This example has been written…
-
How to obtain application property values in a Spring Boot application
In this guide, we will discuss two ways to obtain application property configuration values inside a Spring boot application. We will focus on properties that are loaded via an application.properties or an application.yml file. But all loaded properties in your application context should also be obtainable via the discussed methods. We will discuss the @Value…
-
How to configure Spring beans using constructor injection
In this post, we will focus on configuring Spring beans in a Spring-boot environment using Java configuration and constructor injection. This example should be valid for Spring version 4.3 and later. Let us start by discussing a couple of basic concepts. What is constructor injection? Constructor injection is the process of injecting Spring dependencies into…
-
Reasons why Hamcrest matchers are not so great for Java testing
Hamcrest matchers are great….. not! When asked why use Hamcrest, developers usually site readability and ease of test writing among the most popular reasons for their choice. In this post, we will break down some of these reasons in order for you to make a better choice of frameworks. We will focus on Hamcrests…
-
Java Modulus / Modulo operator – Examples and Uses
The Java modulus ‘%’ operator is one of numerous operators built into the Java programming language. The operator is used to calculate the remainder of the division between two numbers. First, let us discuss how the operator works. How to use the ‘%’ operator The ‘%’ operator requires two operands. The first is the number…
-
JPA / Hibernate – Mapping One-to-One relationships
In this tutorial, we will discuss how to map and configure One-to-One relationships in JPA and Hibernate. What are One-To-One relationships? One to One relationships in databases define the relationship between two different entities, where the first entity can be related to zero or one of the second entity. For example, a user can have…
-
Configure MBeans in Spring boot using Java config and Jolokia
In this article, we will create a new custom MBean. We will show how to configure this bean and then we will test it using Jolokia (JMX over HTTP). Before we start, I highly recommend that you also check our Jolokia and Spring boot tutorial before you proceed as it will make understanding this post much…
-
How to configure Jolokia on a Spring boot server
In this article, we will find out how to configure Jolokia on a Spring Boot 2 server. We will also configure Jolokia on a different management port and a different base URL. Jolokia is a JMX over HTTP bridge that allows system administrators to access their MBeans and JMX functionalities over HTTP and JSON. Getting…
-
The Java Comparable interface – Automatically sort collections
In this post, we will explore how to use the Java comparable interface to automatically sort collections of any classes. We will use the Java Collections from the util library as an example. Why interfaces are so important? Java interfaces are one of the most powerful features of the object oriented programming language. When a…
-
How to improve the performance of ArrayLists in Java
In this post we will discuss the little known trick of setting an ArrayList’s initial capacity to improve the performance of your Java applications and optimizing the usage of the often used data structure. The good news is that it takes a minimal amount of work and can get you a performance boost of up…