How to executes script on different browser?

1) In Mozilla Firefox
   driver = new FirefoxDriver();
2)In Chrome 
   System.setProperty("webdriver.chrome.driver",Add absolute path of chromedriver.exe");
   driver = new ChromeDriver();
3) In IE
   System.setProperty("webdriver.ie.driver","Add absolute path of IEDriverServer.exe");
   driver = new InternetExplorerDriver();
4) In Edge
   System.setProperty("webdriver.edge.driver",Add absolute path of MicrosoftWebDriver.exe");
   EdgeOptions options = new EdgeOptions();
   options.setPageLoadStrategy("eager");
   driver = new EdgeDriver(options);
5) In Opera
   System.setProperty("opera.binary", Add absolute path of opera.exe");
   WebDriver driver = new OperaDriver();
6) In Safari
   System.setProperty("SafariDefaultPath", Add absolute path of Safari.exe");
   WebDriver driver = new SafariDriver();