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



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.