Java Programming Tips


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 (java.io.File) 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 (java.io) 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 […]

Palindrome Program in Java

A string is called a Palindrome if it is spelled the same forward and backward. Following are some examples of palindrome strings, Madam, Noon, Rotor, Rotator, Radar, Malayalam Checking whether a string is palindrome or not is a common programming assignment given to programmers learning a new language. Checking Whether a String is a Palindrome […]

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