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

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better