-2
public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And I don't know what the ? and the : at the end is meaning.

Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;

Can you help me?

Aaron Stein
  • 526
  • 7
  • 18

1 Answers1

1

This statement

Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; 

is equivalent to

Desktop desktop;
if( Desktop.isDesktopSupported() )
    desktop = Desktop.getDesktop();
else
    desktop = null;

Ternary operators is what this is called. <condition> ? <true part> : <false part>

Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43