新建一个Welcom.java文件,注意后缀名是java,不要搞成了java.txt,然后把下面的代码复制进去。
/**
* This program displays a greeting for the reader.
* @version 1.30 2014-02-27
* @author Cay Horstmann
*/
public class Welcome
{
public static void main(String[] args)
{
String greeting = "Welcome to Core Java!";
System.out.println(greeting);
for (int i = 0; i < greeting.length(); i++)
System.out.print("=");
System.out.println();
}
}
cmd命令进到这个文件目录,运行
javac Welcome.java
java Welcome
cmd命令行屏幕显示如下:
E:\corejava\v1ch02\Welcome>javac Welcome.java
E:\corejava\v1ch02\Welcome>java Welcome
Welcome to Core Java!
=====================
E:\corejava\v1ch02\Welcome>