Author Archive


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

How to Rotate an Image Using Affine Transform in Java

Java awt package contains a number of classes for image processing. AffineTransform class can be used for a number of 2D graphics processing requirements. The following Java source code demonstrates the use of AffineTransform to perform 90 degree image rotations. This example preserves the full image after the rotation. If you use the following code […]

How to Securely Store Passwords in Java

One of the common requirements in Java web application is the secure storage of user passwords. You should never store user passwords in plain text. Passwords must be stored in such a way that there should be no way of getting the original password from the stored representation. Cryptographic one way hash functions are perfect […]

How to Write a Coin Toss Game in Java

Check out the following source code for a simple coin toss game written in Java. This game program illustrates the use of Random class and enumerators in Java. The program asks the user to guess the coin toss and then compares the value with the actual coin toss result. Coin toss program runs the game […]