java初学者的一个简单问题

来源:百度知道 编辑:UC知道 时间:2024/05/05 18:38:26
我的jdk是1.4.2
问题是:helloworld.java能编译运行,而几乎同样代码的java程序就不能运行,请看看是为什么?
// HelloWorld.java
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}

// Example.java
class Example{
pubilc static void main(String args[]) {
System.out.println("ni hao!");
}
}
在class Example前面加上pubilc也不行。
提示:
C:\javap>javac Example.java
Example.java:2: <identifier> expected
pubilc static void main(String args[]) {
^
Example.java:5: ';' expected
};
^
2 errors
谢谢各位的参与,环境变量该没有问题,要不为什么helloworld为什么就能运行呢?

class Example{
pubilc(改为public) static void main(String args[]) {
System.out.println("ni hao!");
}
}

应该出示提示什么错误

看看你的类名和这个文件的名字是不是一样的

环境变量设置了没。