Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Java Program to Print Screen Resolution

  • Last Updated : 22 Dec, 2020

Screen resolution can be obtained through a Java program by using Toolkit.getScreenSize() method. getScreenSize() is a method of the java Toolkit class of java.awt package. It gets the size of the screen. On systems with multiple displays, the primary display screen resolution is returned. 

  1. Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
  2. getScreenSize will return the size in pixel.
  3. If directly size is printed, then it is displayed in the format: java.awt.Dimension[width=1366, height=768]


Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

public abstract Dimension getScreenSize()

Returns: The size of the current screen in pixels


HeadlessException (if GraphicsEnvironment.isHeadless() returns true)


// Java code to display the screen size
import java.awt.*;
class GFG {
    public static void main(String[] args)
        // getScreenSize() returns the size
        // of the screen in pixels
        Dimension size
            = Toolkit.getDefaultToolkit().getScreenSize();
        // width will store the width of the screen
        int width = (int)size.getWidth();
        // height will store the height of the screen
        int height = (int)size.getHeight();
        System.out.println("Current Screen resolution : "
                           + "width : " + width
                           + " height : " + height);


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!