Author Archive


ASCII Art Generator Library in Java

ASCII art is a method of creating pictures using the normal printable characters used in computers (ASCII character set). ASCII art can be composed using normal text editors. However this process is very cumbersome. There are a number of software packages available that can convert images or text to ASCII art. If you are looking […]

How to Swap Two Numbers in Java

Swapping two number is easy when you use a temporary variable. The following Java programs swaps two numbers using a temporary variable of the same type. // Java program to swap numbers using temporary variable public class SwapNumbersWithTemp { public static void main(String[] args) { int a = 10; int b = 20; System.out.println("a="+a+",b="+b); int […]

How to List Files in a Directory Using Files.list

Java 8 introduced a number of utility classes intended to improve programmer productivity. The java.nio package was enhanced with a number of new methods. This article explores the list method in java.nio.file.Files class. This new method returns all the entries (files and directories) in the specified directory. However it is not recursive (for recursive use […]

How to Get the List of Running Processes in Mac Using Java

In a Mac machine, the list of all running processes can be retrieved using the following command in the console. The option -e displays all processes including processes owned by other users. The -o command flag instructs ps to show only the command name (with arguments). To get the command name without arguments, use comm […]

How to Iterate Through a Directory Tree in Java

The following example Java program iterates through all the files and directories in a given folder. It also walks through the entire directory tree printing names of sub-directories and files. Note that this example requires Java 8 or above since it uses java.nio.file.Files class and the walk method in it. The following program has 3 […]