While you are testing a web application assume that you have a link and when you clicked on that link it displayed the page in a separate window/tab and if you want to perform actions in that opened window what will be your approach?
Bydeafault web driver can't navigate from one window to another window then you need to use one of the methods to switch from one window to another window.
getWindowHandle() : Returns the current wind handle within this driver instance.
getWindowHandles(): Return a set of window handles which can be used to iterate over all open windows of this WebDriver instance by passing them to switchTo().WebDriver.Options.window().
Synax to switch:
driver.switchTo.window(java.lang.String name or Handle)