Why compiler needs .java suffix but interpreter doesn't need .class suffix?

后端 未结 5 1725
青春惊慌失措
青春惊慌失措 2020-12-21 03:40

To compile Foo.java: javac Foo.java

To run the program : java Foo

Why compiler needs .java suffix but interpre

5条回答
  •  难免孤独
    2020-12-21 04:29

    The Java compiler takes a filename as input, hence Foo.java.

    the Java interpreter takes the fully qualified class name and searches the classpath and current directory for the class. If you use java Foo.class it would search for the class named "class" in the package "Foo", and return NoClassDefFoundError if the class is in the default package, as I understand from your example

提交回复
热议问题