What's the fastest way to draw a Hello World in Java

后端 未结 3 1912
别跟我提以往
别跟我提以往 2021-01-16 02:38

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

3条回答
  •  囚心锁ツ
    2021-01-16 03:06

    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 (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);
        }
    }
    

提交回复
热议问题