public class Test { public static void main(String[] args) { List<Integer> list = new ArrayList<>(Arrays.asList(7, 19, 14, 1, 12, 22, 18, 3, 28, 5)); System.out.println(“Maximum value: ” + Collections.max(list)); System.out.println(“Minimum value: ” + Collections.min(list)); } } Output: Maximum value: 28 Minimum value: 1 Finding the maximum and minimum values in List using the Java 8…
Read More Find Max and Min Values of a List in Java
Output: Java Methods from the StringUtils class that we can use to get a substring from String in Java: import org.apache.commons.lang3.StringUtils; public class Test { public static void main(String[] args) { String str = “Hello, my name is Tom, and I live in USA”; String substringBefore = StringUtils.substringBefore(str, “,”); String substringAfter = StringUtils.substringAfter(str, “,”); String substringBetween = StringUtils.substringBetween(str,…
Read More Get Substring from String in Java
public class TestMultithreading extends Thread { public void run() { System.out.println(“The thread is running…”); } public static void main(String args[]) { TestMultithreading test = new TestMultithreading(); test.start(); } } Output: The thread is running… Get the id and name of a thread public class TestMultithreading extends Thread { public void run() { System.out.println(“ID: “…
Read More Multithreading in Java
In this tutorial, we will cover the basics of serialization and deserialization, including the importance of the ObjectOutputStream and ObjectInputStream classes, the use of the transient keyword, and the implementation of custom serialization methods. We’ll also provide code examples and address some common questions about these concepts. Let’s get started! What are Serialization and Deserialization…
Read More Serialization and Deserialization in Java: A Comprehensive Guide
class ClassA implements Cloneable { private int someNum; private ClassC nestedObjectReference; @Override public Object clone() throws CloneNotSupportedException { ClassA classA = (ClassA) super.clone(); // with this, we are ensuring that deep copy will be performed classA.setNestedObjectReference((ClassC) this.nestedObjectReference.clone()); return classA; } // constructor, getters and setters } class ClassC implements Cloneable { private String classData; public…
Read More What is a Deep Copy in Java?
An important property of modern web apps is resilience. In simple terms, resilience refers to the ability of a system or feature to fail gracefully without impacting the entire system. In the context of web apps, we want to ensure that the entire system will not go down if a remote service, such as a…
Read More Enforcing Resilience in Spring Boot with Resilience4J
In this tutorial, you will learn how to call stored procedures in a Spring Boot RESTful API project that uses Spring Data JPA. Using a stored procedure to execute parts of the application logic in the database is a widely used approach in huge, data-heavy applications. A stored procedure is a group of predefined SQL…
Read More Calling a Stored Procedure in Spring Boot REST with JPA
Reactive Programming Tutorials Introduction to Reactive Programming Introduction to Reactive Streams in Java Project Reactor in Java Create a Mono in Java Reactor Subscribe to a Mono in Java Reactor Extract data from Mono in Java Create a Flux in Java Reactor Subscribe to Flux in Java Reactor Extract data from Flux Convert Mono to…
Read More Java Reactive Programming Tutorials
In this tutorial, you will learn how to create a custom password encoder in a Spring Boot application that uses Spring Security. Table of contents Create a Spring Boot project and add database connection properties, Add a User model, Create a User repository, Implement a custom PasswordEncoder, Create a service class that implements UserDetailService, Add…
Read More Custom Password Encoder in Spring Security
This article is the third of a series on Reactive Programming. If you have not read the previous article, I would strongly advise you to do so. In this article, we will discuss how Reactive Programming is made possible in Spring. Spring WebFlux Spring WebFlux is the Spring project that makes Reactive Programming possible in…
Read More Reactive Programming In Spring Framework
This tutorial will be part of our Series on Reactive Programming in Java and Spring Framework. If you have not read the previous article, I would strongly advise you to do so. This will help you to understand better as we go further. In the previous blog post, we discussed publishers and subscribers in Java.…
Read More Reactive Programming: Creating Publishers and Subscribers in Java.
class Test { public static void main(String[] args) { String name = null; System.out.println(name.toUpperCase()); } } Output: Exception in thread “main” java.lang.NullPointerException at com.example.Test.main (Test.java:9) Here, we got an error message that the NPE has occurred on line 9. Unfortunately, we can’t conclude which value exactly was null from the message. class Test { public static…
Read More Helpful NullPointerExceptions (NPE) in Java
String multilineText= “”” Hi, this is one simple example of a multiline text”””; class Test { public static void main(String[] args) { String example = “{\”key1\”:\”value1\”,\”key2\”:” + “\”value2\”,\”key3\”:\”value3\”}”; System.out.println(example); } } Output: {“key1″:”value1″,”key2″:”value2″,”key3″:”value3”} Now, let’s use a Text Block: class Test { public static void main(String[] args) { String example = “”” { “key1”:…
Read More Java Text Blocks