You can fetch the screen resolution using the Toolkit.getScreenSize() method of Java. Try following the below code:
Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenRes.getWidth();
double height = screenRes.getHeight();
If you have a multi-monitor configuration, you need to use the following :
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
If you want to get the screen resolution in DPI you'll have to use the getScreenResolution() method on Toolkit.
For more info you can refer below:
Hope this helps!
Check out Java certification course to become certified expert.
Thanks!