Java HelloWorld

  | 转载时请务必以超链接形式标明文章原文链接和作者信息及本版权声明。
原文链接:http://www.liaojl.com/archives/2008/05/java-helloworld.html

写一个简单的HelloWorld.java程序,在屏幕上打印一行输出。代码文件名称和类名应该一致,如下所示:

public class HelloWorld {
    public static void main(String args[]) {
        System.out.println("Hello World");
    }
}

编译:

javac HelloWorld.java

执行:

java -cp . HelloWorld

参数-cp是-classpath的缩写,将当前目录添加到ClassPath。否则会报java.lang.NoClassDefFoundError的错误。

Leave a comment

Archives

Creative Commons License
This blog is licensed under a Creative Commons License.