If you want to open the default browser with an URL provided you can use this function. java.awt.Desktop is suitable for windows and xdg-open opens a file or URL in the user's preferred application in linux environment. If a URL is provided the URL will be opened in the default web browser.
public void openDefaultBrowser(URI uri) throws BrowserException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
// windows
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (IOException e) {
throw new BrowserException(e.getLocalizedMessage());
}
} else {
// linux / mac
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("xdg-open " + uri.toString());
} catch (IOException e) {
throw new BrowserException(e.getLocalizedMessage());
}
}
}
firefoxcommand can take a command line argument indicating the URL to go to. I'm not sure what "execute certain commands" means, but if you're looking to perform actions on a webpage, you want a web driver like Selenium (Selenium was originally written in Python, but based on the website it looks like they have a Java version)