Essentially, driver.getTitle(); function can be used to get the title of a page. So Aniket's code will also work, but there would be complications. So i'll just explain it a little better (hopefully :P).
WebDriver driver = new FirefoxDriver();
String title = driver.getTitle();
System.out.println("Title is: ", +title);