In this post, we will discuss two different types of Spring beans, namely singleton and prototype beans. We will also discuss when is it preferred to use prototype beans and when to use singleton beans. Singleton beans Most beans that you will use or encounter are singleton beans. Singleton beans are initialized only once. Either […]
How to find prime numbers using Java
In this post, we will discuss how to write a simple Java program to find prime numbers between 1 and 100. We will be using a simple algorithm implemented in nested loops. So let us get started! What is a prime number? A prime number is a number which can only be divided by 1 […]
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 […]
Troubleshooting a PropertyNotFoundException in JPA
In this post, we discuss yet another reason for having a mapping error from Hibernate. This specific one is called a PropertyNotFoundException. If you have made sure that your property is correctly mapped to the database table, with correct column names and a getter and a setter for the property, then read on!. Let us […]
Java – Convert a decimal number to and from a binary number
In this tutorial, we will discuss how to convert a decimal number to binary and back to a decimal. This can easily be done by preexisting Java functionalities. But for the sake of curiosity, let us implement our own algorithm first, and then let us discuss how to do with existing Java functions. Algorithm […]
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 […]