Java Programming Tips


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

How To Subtract Two Matrices in Java

Matrix operations are important in a number of programming problems in the areas of image processing, probability theory and physics simulation. Matrix subtraction is simple, and it involves subtracting each entry in the second matrix from the corresponding entry in the first matrix. The following Java program demonstrates matrix subtraction. This example uses constant matrices […]