Author Archive


How to Remove all Spaces from a String in Java

The following Java program removes all space characters from the given string. Please note that this program doesn’t work if you want to remove all whitespaces (not just spaces!) from a string. // Java Example Program to remove all spaces from a String public class RemoveSpacesExample { public static void main(String[] args) { String input […]

How to Create Deadlock in Java

A deadlock can occur in Java multithreaded programs when one thread is waiting on another thread and vice versa. Since each thread is waiting, the program is deadlocked and cannot proceed. A deadlock can be simulated in a multi-threaded program if there are two resources and two threads. Let us call them R1/R2 and T1/T2. […]

Quick Microservice Prototyping With Spring Boot CLI

Spring boot command line interface (CLI) can be used to quickly create microservice backend prototypes. If you are not familiar with spring boot cli, see our earlier articles – introduction to spring boot cli and introduction to spring boot framework. In this article, I will show you how quickly you can create spring based microservice […]

How to Write a BMI Calculator in Java

BMI stands for Body Mass Index. It is a measure of body mass based on height and weight of an individual. Using the range of BMI, individuals are classified as underweight, normal or overweight. Its value is in a specific range for a healthy individual. The following table shows the main BMI categories. Category BMI […]

How to Zip a Folder in Java

Java has a good library of classes for handling zip files. These classes are available in the java.util.zip package. The following example program in Java shows how you can use java.util.zip classes to create a zip of an entire folder. We use the Files.walkFileTree to recursively navigate through the directory tree and then add each […]