Search results for: Java

In this article, you will learn how to perform user authentication with Amazon Cognito in a Spring Boot application. But before we dive into that, let’s first explore what Amazon Cognito is. According to what’s mentioned on the AWS official website: Amazon Cognito lets you add user sign-up, sign-in, and access control to your web…

Read More User Authentication with Amazon Cognito in Spring Boot Application

In this tutorial, you will learn how to write a JUnit test that validates whether the method under test throws the correct exception. The tutorial includes examples for both JUnit 5 and JUnit 4. For video lessons, check out my video course: Testing Java with JUnit and Mockito. Let’s begin with JUnit 5 version first.…

Read More Test for Exception in JUnit 5 and JUnit 4

Optional<T> findFirst() class Test { public static void main(String[] args) { List<Integer> numbers = new ArrayList<>(Arrays.asList(3, 7, 9, 12)); Optional<Integer> resultOptional = numbers.stream().findFirst(); if (resultOptional.isPresent()) { // checking if Optional contains any value System.out.println(“The first element in the stream is: ” + resultOptional.get()); // getting the value from Optional } else { System.out.println(“The stream is…

Read More Streams – findFirst() operation

Maven is a popular build tool for Java projects. It helps you manage dependencies, build and test your projects, and package them for distribution. Keeping Maven up-to-date is important to take advantage of the latest bug fixes and new features. If you do not have Maven installed on your computer, then read How to install…

Read More Upgrading Maven on macOS

Spring is a popular Java-based framework for building applications. One of its core features is dependency injection, which is used to manage the relationships between objects and to make it easier to manage the dependencies in an application. In this tutorial, we will explore two of the main methods of dependency injection in Spring: constructor…

Read More Constructor vs Field Dependency Injection in Spring

In this article, we will learn about Many-to-Many relationships in JPA and how to implement them in a Spring Boot application. Let’s get started! @ManytoMany annotation A many-to-many relationship occurs when multiple records in one table are associated with multiple records in another table. The @ManyToMany annotation is used to define a many-valued association with…

Read More Many-to-Many Relationship in Spring Boot Rest with JPA

Dependency Injection is a design pattern that allows the separation of concerns in an application by removing the hard-coded dependencies between objects. In Dependency Injection, the objects are provided with their dependencies instead of having to hard-code them. This makes the application more flexible, maintainable, and easier to test. Spring Framework provides several ways to…

Read More Field-based Dependency Injection in Spring

In this tutorial, you will learn how to download and start up Keycloak as a standalone server. What is Keycloak? Keycloak is an open-source identity and access management tool focusing on modern applications and services such as mobile applications, REST APIs, and single-page applications. How to Download Keycloak? To download the Keycloak go to the…

Read More Keycloak: Starting a Standalone Server

In this Spring Security tutorial, you will learn how to enable Basic Authentication for your Spring Boot project and configure the default username, password and user role. You will also learn how to secure a web service request URL so only authenticated users with a default username, password and role can access it. If you use…

Read More Spring Security Default Username, Password, Role

RESTful web services use HTTP methods and representations to manage resources. In order to properly handle these resources, it’s important to understand how to define the expected behaviour of an endpoint in terms of the HTTP request and response, including specifying request methods, headers, and media types. By using Spring’s @RequestMapping annotation, we can map…

Read More The @RequestMapping Annotation: A Comprehensive Guide

Spring Framework is an open-source application development framework that provides comprehensive infrastructure support for developing Java applications. One of the key features of the Spring Framework is its support for stereotype annotations, which provide a convenient way to configure and manage the various components in a Spring-based application. What are Stereotype Annotations? Stereotype annotations are…

Read More Spring Boot Stereotype Annotations

Core Spring Framework Annotations are a set of annotations that are used to simplify the development process of Java applications using the Spring Framework. These annotations can be used to inject dependencies, define components, and specify configuration details without the need for explicit XML configuration. Some of the most commonly used Core Spring Framework Annotations…

Read More Spring Core Annotations with Examples