Friday, September 5, 2025
HomeLanguagesJavaJava Program to Print Screen Resolution

Java Program to Print Screen Resolution

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]

Declaration

public abstract Dimension getScreenSize()

Returns: The size of the current screen in pixels

Exception

HeadlessException (if GraphicsEnvironment.isHeadless() returns true)

Java




// 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);
    }
}


Output:

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS