Search results for: Maven

This tutorial is about creating Lambda functions from Spring Cloud Functions. Spring Cloud Functions provide a way to implement the business logic via functions and decouple code development from the runtime target. Hence, the developer can focus solely on the implementation of logic. The developer need not worry about the target endpoint type, connectivity, integration,…

Read More Create AWS Lambda Functions from Spring Cloud Functions

In this tutorial, we are going to see how we can use the AWS API Gateway as a trigger to an AWS Lambda function. This tutorial requires you to be familiar with building and deploying Serverless Applications with AWS Lambda. Prerequisite: Build and Deploy a Serverless Spring Boot Web Application with AWS Lambda Firstly, add…

Read More Trigger a Lambda Function Using AWS API Gateway

Build and deploy a Serverless Spring Boot Web Application with AWS Lambda This is a tutorial about creating a basic AWS Lambda function in Java using the Spring framework and requires you to have an active AWS account. If you don’t, go ahead and create one. Lambda is the serverless compute service provided by the…

Read More Build and deploy a Serverless Spring Boot Web Application with AWS Lambda

To convert String to boolean in Java, you can use one of the following methods: Boolean.parseBoolean() method BooleanUtils.toBoolean() method Boolean.valueOf() method if we need a Boolean object instead of a primive Convert String to boolean in Java using the Boolean.parseBoolean() method With the parseBoolean(String s) method of the Boolean class, if we want to get…

Read More Convert Java String to boolean

Want to learn how to merge two ArrayLists in Java? In this post, we will cover the following ways: Using the List.addAll() method Using the Java 8 Streams Using the ListUtils.union() method Merge two ArrayLists in Java using the List.addAll() method There is addAll() method from the List interface that appends all of the elements in…

Read More How to merge two ArrayLists in Java?

This tutorial will demonstrate how to implement the One-to-Many Mapping in your Spring Boot application that uses Hibernate/Spring Data JPA. As a database, I will use a MySQL server. If you are learning about Hibernate, you might also be interested in the following tutorials: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL Many-to-Many Relationship in…

Read More One to Many Mapping Hibernate/JPA Using Spring Boot and MySQL

This tutorial will demonstrate how One-to-One Mapping in Hibernate/Spring Boot Data JPA works. As a database, I will use a MySQL database server. We will create two JPA entities: the Book and the Story. The Book and the Story entities have one to one relationship, which means that the Book entity has a Story entity,…

Read More One to One Mapping Hibernate/JPA Using Spring Boot and MySQL

We often need to compare two ArrayList in Java. In this post, you will learn how to do that in two ways: Using the ArrayList.equals() method Using the CollectionUtils.isEqualCollection() method Compare two ArrayList in Java using the ArrayList.equals() method The ArrayList.equals() method compares two ArrayList. It compares the sizes of the lists, elements equality, and the…

Read More Compare two ArrayList in Java

Sometimes we need to consume HTTPS endpoints that do not have valid certificates.  We can do that by configuring the Java HttpClient to accept all SSL certificates, even from an untrusted Certificate Authority. Here you will see how to communicate with HTTPS endpoint that may not have a valid SSL certificate. In the following example,…

Read More Java HttpClient – Accept all SSL Certificates

<dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.5.13</version> </dependency> import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpDelete httpget = new HttpDelete(“https://jsonplaceholder.typicode.com/todos/1”); System.out.println(“Executing DELETE request…”); HttpResponse response = httpclient.execute(httpget); System.out.println(“Status code: ” + response.getStatusLine().getStatusCode()); String…

Read More How to Execute an HTTP DELETE Request in Java (Solved!)

<dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.5.13</version> </dependency> import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpPut httpPut = new HttpPut(“https://jsonplaceholder.typicode.com/posts/1”); // specify the PUT body to send to the server as part of…

Read More How to Execute an HTTP PUT Request in Java

<dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.5.13</version> </dependency> import org.apache.http.HttpResponse; import org.apache.http.entity.StringEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(“https://jsonplaceholder.typicode.com/posts”); // specify the POST body to send to the server as part of…

Read More Execute an HTTP POST Request in Java

<dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.5.13</version> </dependency> import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpGet httpget = new HttpGet(“https://jsonplaceholder.typicode.com/todos/1”); System.out.println(“Executing GET request…”); HttpResponse response = httpclient.execute(httpget); String responseBody = new BasicResponseHandler().handleResponse(response); System.out.println(“Response: ” +…

Read More Execute HTTP GET Request in Java

public class Test { public static void main(String[] args) { Integer[] array = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // reverse an array Integer[] reversedArray = reverse(array); // print the elements Arrays.stream(reversedArray).forEach(item -> System.out.print(item + ” “)); } public static Integer[] reverse(Integer[] array) { List arrayList = Arrays.asList(array); Collections.reverse(arrayList); return…

Read More Reverse an Array in Java