在Java中绘制Hello World的最快方法是什么
使用Java中的GUI在屏幕上绘制Hello World的最快方法是什么:
1-通过使用最少的类数。
2-执行最少字节代码
3- JVM调整
因此,当我双击Windows中的Jar文件时,Hello World会立即出现(假设尚未加载运行时)。
这是我能得到的最快的图形化Hello世界。
public class HelloWorld{ public static void main(String[] args) { javax.swing.JOptionPane.showMessageDialog(null, "Hello World"); } }
SplashScreen
类很难被击败,因为它甚至可以在JVM启动之前显示图像,但我不确定它是否有资格获得“GUI”。
使用空的main()
(导致带有Win XP JDK6的370字节类文件), java -splash:helloworld.png
(或jar)的运行速度比闪烁时快。
或者您可以使用这个简单的类来控制您将看到图像的时间:
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); } }
如果您正在优化运行时,则使用文本“Helo World”预渲染图像,然后使用Java将其显示为图像。 您可以使用ImageIcon
轻松显示图像。