6,java代码测试 写一个简单的java测试类Test.java,然后编译运行java程序,如下所示: [root@name01 tim]# vim Test.java public class test { public static void main(String args[]) { System.out.println("A new jdk test !"); } } 保存退出,编译Test类 [root@name01 tim]# javac Test.java Test.java:1: error: class test is public, should be declared in a file named test.java public class test { ^ 1 error 报错,需要把类名和java文件名统一一起来,不然没法编译 [root@name01 tim]# vim Test.java
public class Test { public static void main(String args[]) { System.out.println("A new jdk test !"); } } 保存退出,然后编译 [root@name01 tim]# javac Test.java [root@name01 tim]# [root@name01 tim]# ll Test* -rw-r--r--. 1 root root 418 Aug 22 09:22 Test.class -rw-r--r--. 1 root root 114 Aug 22 09:21 Test.java [root@name01 tim]# 编译成功,多出了Test.class可执行文件,然后执行看执行结果,如下所示: [root@name01 tim]# java Test A new jdk test ! [root@name01 tim]#