Constants in Java

Java language has a reserved word const intended for future use. However this keyword was never implemented and has no function. The original intent of the const keyword was to implement readable only references (which means a const reference cannot be used to modify object instance). However Java language designers decided NOT to implement this […]

Recursively Listing Files in a Directory in Java

Using the File class in Java IO package ( you can recursively list all files and directories under a specific directory. There is no specific recursive search API in File class, however writing a recursive method is trivial. Recursively Listing Files in a Directory The following method uses a recursive method to list all files […]

How to Get List of Files in a Directory in Java

Java IO package ( provides class named File which is abstraction of file and directory names. This class provides an abstract, system independent view of path names. The following sample Java program prints a list of files and folders in a specified directory. The program also uses File attributes to indicate whether a directory entry […]

Reading a Text File in Java

Java has an extensive API for file handling. The following code illustrates how Java File API can be used to read text files. This example shows line by line reading of the file content. This example also assumes that a text file with the name input.txt is present in the C:\ drive. If you are […]

Creating a Random BigInteger in Java

Java provides a custom class named BigInteger for handling very large integers (numbers which require more than 64 bits). BigInteger provides a constructor using which you can create a random BigInteger value. public BigInteger(int numBits, Random rnd) Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2^numBits – 1), inclusive. The uniformity […]