Author Archive


How to Rename a File in Java

Java provides a built-in class java.io.File for standard file operations. This can be used for renaming files as well. The following example shows how a file can be renamed in Java. import java.io.File; /** * How to rename a file in Java 7 and below. * @author jj */ public class RenameFile1 { public static […]

Finding Perfect Square Numbers in a Range Using Java

Perfect square numbers are natural numbers which can be expressed in the form n = a * a. Hence any number which is the result of multiplying a number with itself is known as a perfect square number.  For example, 9 is a perfect square number since 9 = 3 * 3. Finding Perfect Square […]

How to Generate MD5 Hash in Java

A key concept in cryptography is the concept of hash values. A hash is a unique value corresponding to a given data with the following properties, It is impossible to arrive at the original message from hash. Two different messages practically cannot have the same hash. Modifying message changes the corresponding hash. It is easy […]

How to Download a File in Java

Nowadays any non trivial application written in Java would need to access cloud services over HTTP. Whether you are accessing a cloud web service or trying to download a webpage programmatically, the approach is same. Java provides a dedicated class HttpURLConnection for getting data over the HTTP protocol. The following sample Java program demonstrates the […]

How To Generate SHA256 Hash in Java

In cryptography, SHA (Secure Hash Algorithm) is a hash function which generates a unique value for a given data. This unique value (known as hash) has the following properties, It is impossible to arrive at the original message from hash. Two different messages practically cannot have the same hash. Modifying message changes the corresponding hash. […]