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

后端 未结 5 1691
青春惊慌失措
青春惊慌失措 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:16

    Adding to David Zaslavsky's explanation:

    The java source code are not necessarily from .java files either. We can have a compiler that takes source code from difference character streams, as in the API javax.tools.JavaCompiler.

    The cmd line util javac happens to be working with file sources only, so it desires file paths.

提交回复
热议问题