How To Get Screen Resolution In Java

This post highlights the one of the feature of¬†Toolkit class in Java. If you are working on web application or desktop development, the common standard is to render the screen for the user’s current resolution. Each user may have the different resolutions and screen sizes. It is very simple to get the current screen size using the Java program. Also this will work on any operating system.

Lets look at the example below.


import java.awt.Dimension;
import java.awt.Toolkit;

public class ScreenSizeExample {
	public static void main(String[] args) throws IOException{
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		System.out.println(screenSize.getWidth() + " x " + screenSize.getHeight());


1366.0 x 768.0

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!