What\'s the fastest way to draw a Hello World on the screen using a GUI in Java:
1- by using the minimum number of classes.
2- with the leas
this is the fastest graphical Hello world i could get.
public class HelloWorld{
public static void main(String[] args) {
javax.swing.JOptionPane.showMessageDialog(null, "Hello World");
}
}
The SplashScreen class would be tough to beat as it can display an image even before JVM starts, though I'm not sure if it qualifies for a "GUI".
With an empty main()
(which results in a 370-byte class file with Win XP JDK6), java -splash:helloworld.png <class>
(or a jar) would run faster than you can blink.
Or you can use this trivial class to control how long you'll see the image:
public class DoNothing
{
public static void main(String[] args) throws InterruptedException
{
int i = 1000;
if( args != null && args.length > 0 )
try{ i = Integer.parseInt(args[0]); }
catch( NumberFormatException ex ) {}
Thread.sleep(i);
}
}
If you're optimizing for runtime then pre-render an image with the text "Helo World" and then use Java to display it as an image. You can use ImageIcon
to easily display an image.