Java Programming Tips


How to Implement Bubble Sort in Java

Bubble sort is one of the simplest and easy to understand sort algorithm. It works by comparing each pair of adjacent elements in a list and swapping them if they are in wrong order. This swapping process is repeated for the entire set of elements again and again until no swaps are detected. At this […]

How to Parse a CSV file in Java

A CSV file is a simple text file used to store tabular data. Each line is a record of data and consists of fields separated by commas. The main advantage of CSV file format is that it is portable and human readable. Files using proprietary formats such as Microsoft excel files can be exported to […]

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. […]

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 […]