Java Programming Tips


How to Copy Files from One Folder to Another in Java

The following Java program copies files with .java extension from one folder to another folder. You can easily change the extension .java to anything you want. For example, you might want to copy just .txt files from one directory to another. This program takes two input parameters. The first one is the source directory and […]

Array to Map Conversion in Java

Converting an array of strings to a map of strings with the same string as key and value is required in many use cases. Conversion to map enables quick and easy evaluation as to whether a string exists in the list of strings. Conversion to map also enables removal of duplicate strings. The following Java […]

How to Print a Number Pyramid in Java

The following Java program prints a sequential number pyramid in Java. The output of the program is given below.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15   /** * Prints number pyramid Java * @author jj */ public class NumberPyramid { public static void main(String[] args) […]

Java Program to Find Repeated Words in a String

The following Java program prints repeated/duplicated words in a String. The program uses case insensitive comparison (For example, program assumes words CAT, cat and Cat etc. are all same). This algorithm is useful in text processing programs where word frequency calculations are needed. The program first asks for the input string from the command line. […]

Area of a Circle in Java

The formula for calculating area of a circle is, Area = PI * r * r, where PI is a constant and r is the radius of the circle. The following sample Java program calculates area of a circle. The radius of the circle is taken as user input from command line. The default Java […]