You can use something like this:
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String message = "Hello World!";
JOptionPane.showMessageDialog(null, message, "Message",
JOptionPane.INFORMATION_MESSAGE);
}
}
To show a dialog box in OnlineGDB, instead of clicking "Run" you need to choose the drop down beside it and choose "Run with display screen (beta)"