How to get window size, resize or maximize window using Selenium WebDriver ?

@Test
public void BrowserwithGivenDimension() throws Exception
{
driver.get("
http://seleniumsubbu.blogspot.in/");
driver.manage().window().maximize();//The 
standard layout is for desktops, laptops and other large screen devices.
System.out.println(driver.manage().window().getSize());
Thread.sleep(5000);
driver.get("
http://seleniumsubbu.blogspot.in/");
Dimension n = new Dimension(580,768); //Tablet devicessuch as iPad, Android and Windows tablets have two orientations
driver.manage().window().
setSize(n);
System.out.println(driver.manage().window().
getSize());
Thread.sleep(5000);
driver.get("
http://seleniumsubbu.blogspot.in/");
Dimension k = new Dimension(320,580); //
Smalltouch devices
such as iPhone, Android and Windows phones
driver.manage().window().setSize(k);
System.out.println(driver.manage().window().getSize());
}