Java Programming Tips


Guess the Number Game in Java

In guess the number game, the computer program will come up with a random number within a range (for example, 1 to 1000). The player (user) is asked to guess this number. If the guessed number is bigger than the actual number, the computer will respond with the message "too high". If the guessed number […]

How to Encrypt and Decrypt Data In Java Using AES Algorithm

AES (Advanced Encryption Standard) is a strong symmetric encryption algorithm. A secret key is used for the both encryption and decryption of data. Only someone who has access to the same secret key can decrypt data. AES encryption provides strong protection to your data. The following sample Java program shows how to encrypt data using […]

How to Generate Random Numbers in a Range in Java

Random numbers are used in a number of programming applications such as games, computer simulation, cryptography etc. It is also used to generate test data. Usually you want to generate random numbers in a specific range of values. The following example program in Java generates 5 random numbers between 10 and 20 (both inclusive). import […]

How to Print Arrays in Java

When working with arrays in Java, it is useful to print the array contents on the console or on the log file. This is useful for debugging the application. It is possible to print one dimensional or multi-dimensional arrays using for loops. However a much easier solution is to use the deepToString() static method of […]

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