Java Programming Tips

Towers of Hanoi Recursive Solution in Java

Towers of Hanoi is a well known mathematical game/puzzle involving three pegs and a number of discs. The size of the discs are different and they are kept on the source peg with the smallest on the top and the biggest one on the bottom. The aim of the game is to move all the […]

Dice Roller in Java Source Code

A six faced dice is used in various gambling games. The following Java program simulates the standard 6 face dice game. The program uses an infinite loop to roll dice until the user decides to exit the program. In addition to printing the face value, the following program can also draw the dice face using […]

How to Remove Extension from Filename in Java

The following function removes extension from a filename using Java. However it will not modify the hidden file names in mac/linux which starts with a dot character. A different implementation is available as part of the Apache commons IO library. // Java example: removes extension from a file name. public class ExtensionRemover { public static […]

How to Resize Image in Java

Java has built-in API for resizing images in java.awt package. The code example below uses the Graphics2D and BufferedImage classes to resize all images in a directory. The ImageIO class supports a number of file formats such as jpeg, png, gif and bmp. The code below uses a percentage value for resizing the image. This […]

How to Open a New Window in JavaFX

If you are just getting started on JavaFX, Please read this JavaFX tutorial first. Usually a non trivial JavaFX application will have more than one window(stage). The following Java example shows how to open a new window in JavaFX. It also shows how to pass data from one stage(window) to another stage. Please note that […]