Spring Boot and Ehcache 3 Example

Learn to configure Ehcahce 3 with Spring Boot 2.x and Spring Boot 3.x applications, use @Cacheable annotation and log caching events.a

Count Vowels and Consonants in Java

Learn the different ways of counting the number of vowels and consonants in a given string using the Java 8 Streams and simple iteration.

Java program to reverse words in string without using functions

In these java programs, learn to reverse the words of a string in Java without using api functions. We can reverse the words of string in two ways: Reverse each word’s characters but the position of word in string remain unchanged. Reverse the string word by word but each word’s …

Regex – Match Any Character(s)

In regex, we can match any character using period “.” character. To match only a given set of characters, we should use character classes.

Regex – Match Start or End of String (Line Anchors)

Regular expressions, commonly referred to as regex, are powerful tools for pattern matching and manipulation of text. The regex patterns enable developers to perform intricate string searches, substitutions, and validations. Among the plethora of regex features, line anchors are the key components for precisely identifying the beginning or end of …

Java program to swap two numbers

Learn to swap two numbers in given two Java programs. First program uses a temporary variable while second program does not uses any temp variable.

Spring WebMVC Optional @PathVariable

Learn to have optional @PathVariable valuein spring mvc application when required attribute to set to false or expect variable’s value to null.

Configure Hibernate with Spring Boot

Learn to configure hibernate/JPA support in Spring Boot2 applications, along with creating entity classes and extending inbuilt JpaRepository interfaces.

Spring Boot Embedded Server Logs

Learn to enable and customize the internal and access logs generated for embedded servers in Spring boot e.g. tomcat, jetty & undertow.

How to Shutdown a Java ExecutorService

Learn ExecutorService shutdown(), shutdownNow() and awaitTermination​() APIs and how to use them correctly to shutdown executor under different conditions,

Java ExecutorService invokeAll()

Learn to run multiple Callable tasks with ExecutorService.invokeAll(tasks) API and processing all the results returned from tasks in form of Future class instances in this ExecutorService Callable example.

ExecutorService invokeAny()

Learn to use ExecutorService invokeAny() method where we execute multiple tasks at same time, but we make a decision asap any one of tasks is completed.

Executor RejectedExecutionHandler

Learn to handle tasks which are submitted to Executor and are rejected because the executor has been shutdown for any reason using RejectedExecutionHandler. 1. When tasks get rejected Remember when we finish the execution of an executor, we use the shutdown() method. The executor waits for the completion of tasks …

Guide to ExecutorService in Java

Learn to use Java ExecutorService to execute a Runnable or Callable class in an asynchronous way. Also learn the various best practices to utilize it in most efficient manner in any Java application.

Compact Number Formatting in Java

Learn to apply locale-sensitive compact/short number formatting to general purpose numbers e.g. decimal, currency, and percentage. It is added in Java 12 in CompactNumberFormat class.

Java 11 Files.readString()

Learn to read a file to string in Java using Files.readString(path) method. This API has been introduced in Java 11.

Collectors teeing() Examples

Learn about Collectors.teeing() method (added in Java 12), method syntax and how to apply teeing() method in various usecases in Java.

Java 11 new features and enhancements

Java 11 (released on September 2018) includes many important and useful updates. Let’s see the new features and improvements, it brings for developers and architects. 1. HTTP Client API Java had HttpURLConnection class for long time for HTTP communication. But over the time, requirements have gone complex and more demanding …

Java 12 – New features and enhancements

Java 12 (released on March 19, 2019) is latest version available for JDK. Let’s see the new features and improvements, it brings for developers and architects.

Java Program to Check Deficient number

Learn to write a simple java program to verify if a given number is deficient number or not. The value 2n − σ(n) is called the number’s deficiency.

Spring MVC Validation of Request Body and Parameters

Learn to validate the request body of a REST API built with Spring MVC. Also, validate @PathVariable and @RequestParam parameters in resource URIs using the hibernate validator framework. In this Spring MVC validation example, we will add validations in REST APIs created for the CRUD example. 1. Request Body Validation …

Spring Custom Token Authentication Example

Learn to add custom token based authentication to REST APIs using created with Spring REST and Spring security 5. In given example, a request with header name “AUTH_API_KEY” with a predefined value will pass through. All other requests will return HTTP 403 response.

Compare Two LocalDateTime Instances

Learn to compare two LocalDateTime instances to find out which date represents an older timestamp in comparison to other timestamp. LocalDateTime class is part of java.time package added in Java 8.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.