Open In App

Java Program to Open Input URL in System Default Browser in Windows

Last Updated : 19 Jan, 2021
Like Article

URL is the URL you want to display in the default Web browser. For example, wire to this input to display the HTML file report.html on the Web Server in the browser.

Our problem is to write a java program to open Input URL in System Default Browser in Windows.

To open any URL we use different predefine files of java to operate with our Desktop.

  1. java.awt.Desktop: We use java.awt.Desktop class because java.awt.Desktop allow us to interact with different capability of our Desktop. For Example Launching User default Browser, Launching user default mail Client etc.
  2. is used to Represent User Resource Identifier reference.


  • Firstly, we create an Object of our-defined class that we import by java.awt.Desktop.
  • During the creation of an object, we use getDesktop() method that returns the Desktop instance of the current desktop context. On some platforms the Desktop API may not be supported, in that case we use isDesktopSupported() method to determine if the current desktop is supported.
  Desktop desk=Desktop.getDesktop();
  • Then we use browse() method where we enter our URL that we want to open on our desktop by new URI().
  desk.browse(new URI(""));


// Java Program to Open Input URL in 
// System Default Browser in Windows
import java.awt.Desktop;
class GFG {
    public static void main(String[] args)
             throws Exception
        Desktop desk = Desktop.getDesktop();
        // now we enter our URL that we want to open in our
        // default browser
        desk.browse(new URI(""));


(Our URL "" will open in our desktop default browser)

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads