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.

ScreenSizeExample.java

package javabeat.net.core;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;

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

Output…

1366.0 x 768.0

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>