Get browser version and browser name using selenium ?

@Test
public void printBrowerNameandVersionNameandOSName2() throws Exception
{


String s = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
System.out.println("Browser name : " + s);

}