selenium webdriver set window size using dimension

java.awt.Dimension screenSize = Toolkit.getDefaultToolkit()
.getScreenSize();
Dimension dimension = new Dimension(screenSize.width, screenSize.height);
driver.manage().window().setSize(dimension);

and if you are getting any exception like this in linux

java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.

1. using terminal check echo $DISPLAY and set display using

export DISPLAY=<hostname_to_display_X11_graphics_to>:0.0

2. Then run the test again.

No images available.